What is the purpose of using mysql_num_rows() function in PHP?
The purpose of using the mysql_num_rows() function in PHP is to retrieve the number of rows returned by a SELECT query executed on a MySQL database. This function is useful for determining the number of results returned by a query, which can be used for various purposes such as displaying the count of search results or implementing pagination.
// Connect to the database
$conn = mysqli_connect("localhost", "username", "password", "database");
// Execute a SELECT query
$query = "SELECT * FROM users";
$result = mysqli_query($conn, $query);
// Get the number of rows returned by the query
$num_rows = mysqli_num_rows($result);
// Display the count of rows
echo "Number of rows: " . $num_rows;
Keywords
Related Questions
- Is there a specific reason for checking the user agent in the PHP script to determine the browser type, and are there any drawbacks or best practices associated with this approach?
- What are the potential risks of storing SMTP credentials in a PHP file for email sending?
- How can PHP developers effectively troubleshoot and debug issues related to CSS class assignment in HTML elements generated dynamically by PHP code?