Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a PHP function to return multiple rows from a mysql query?

Tags:

sql

php

mysql

I'm relatively new to php, and to this point I've been fine using the mysql_fetch_array function to echo values selected from the database. But now I want to be able to echo the results selected from multiple rows with the same username.

I was just wondering what the most efficient way of doing this was. I could manage to do it using a for loop and counting through each individual query, but I know there must be a more efficient way just using sql, or using a better oho function.

Thank you for the help.

Alex


1 Answers

while($row = mysql_fetch_array($result)) { 
    // process each row
}

I guess that's all you neeed - have a play and you should get your desired effect! It's best to do it in PHP..

Also you shouldn't use mysql_fetch_array anymore as it's deprecated. Use PDO or mysqli insted. More information you can find here

like image 75
Moseleyi Avatar answered Jun 04 '26 02:06

Moseleyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!