Home >Backend Development >PHP Tutorial >Why Is My MySQL Query Returning Only One Row When I Expect Multiple?
MySQL Returns Multiple Rows Rather Than One
When retrieving data from a database using MySQL, it's possible to encounter situations where only one row is returned, despite expecting multiple. To address this issue, consider the following explanation.
In the example provided, the SQL query in PhpMyAdmin returns multiple rows successfully. However, the PHP code does not handle the retrieval of these rows correctly. Here's a modified version of the PHP code that will output all rows matching the query:
<code class="php">$query = mysql_query("SELECT `title`, `url_title` FROM `fastsearch` WHERE `tags` LIKE '%$q%' LIMIT 5"); while ($row = mysql_fetch_assoc($query)) { print_r($row); }</code>
In this corrected code:
The above is the detailed content of Why Is My MySQL Query Returning Only One Row When I Expect Multiple?. For more information, please follow other related articles on the PHP Chinese website!