dzedward Posted June 5, 2008 Share Posted June 5, 2008 Say I have a query like so: $sql = mysql_query("SELECT * FROM $my_table WHERE username='$user'"); But, there are more than one entries where username would equal $user. I want to get all the data basically where that condition matches. Is this possible by chance? Thanks. Link to comment https://forums.phpfreaks.com/topic/108860-php-mysql_query-return-multiple-rows/ Share on other sites More sharing options...
jonsjava Posted June 5, 2008 Share Posted June 5, 2008 do they have passwords you can check against? you could then do $sql = mysql_query("SELECT * FROM $my_table WHERE username='$user' AND password='$password';"); Link to comment https://forums.phpfreaks.com/topic/108860-php-mysql_query-return-multiple-rows/#findComment-558421 Share on other sites More sharing options...
dzedward Posted June 5, 2008 Author Share Posted June 5, 2008 That does the same thing. Lets say there are 3 matches for username=$user name, well that is ok, and I want all the results to get returned, however, it only returns results for the first match it encounters. Link to comment https://forums.phpfreaks.com/topic/108860-php-mysql_query-return-multiple-rows/#findComment-558423 Share on other sites More sharing options...
Buddski Posted June 5, 2008 Share Posted June 5, 2008 if you want to loop though all the entries use this <?php echo '<pre>'; $sql = mysql_query("SELECT * FROM $my_table WHERE username='$user'"); if (mysql_num_rows($sql) > 0) { while($data = mysql_fetch_array($sql)) { print_r($data); } } else { echo 'No Results'; } echo '</pre>'; ?> That will print the results for each match found Link to comment https://forums.phpfreaks.com/topic/108860-php-mysql_query-return-multiple-rows/#findComment-558430 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.