Suppose we have a "websites" table with 5 fields and 20 rows. Return the number of columns for the most recent query:
<?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(); } mysqli_query($con,"SELECT * FROM websites");//Get the number of columns echo mysqli_field_count($con);mysqli_close($con);?>
The mysqli_field_count() function returns the number of columns recently queried.
mysqli_field_count( connection ) ;
parameter | describe |
---|---|
connection | Required. Specifies the MySQL connection to use. |
Return value: | Returns an integer representing the number of columns in the result set. |
---|---|
PHP version: | 5+ |