Get the field information of all fields, then get the current field through mysqli_field_tell() and output the field name, table and maximum length:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT name,url FROM websites ORDER BY alexa";if ($result=mysqli_query($con,$sql)){ //Get all field information while ($fieldinfo=mysqli_fetch_field($result)) { //Get the current field information$currentfield=mysqli_field_tell( $result); printf("Column %d", $currentfield); echo "<br>"; printf("Field name: %s", $fieldinfo->name); echo "<br>"; printf("Table name: %s", $fieldinfo->table); echo "<br>"; } // Release the result set mysqli_free_result( $result);}mysqli_close($con);?>
The mysqli_field_tell() function returns the location of the field pointer.
mysqli_field_tell( result ) ;
parameter | describe |
---|---|
result | Required. Specifies the result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result(). |
Return value: | Returns the current offset of the field pointer. |
---|---|
PHP version: | 5+ |