Reputation:
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
Upvotes: 3
Views: 2049
Reputation: 1838
SQL is used to query the database your using. PHP is used to format the output from the query. See the manual from PHP.net for more info php.net/manual/en/function.mysql-fetch-array.php . There is no way as far as I know to format the output in rows using SQL.
B.T.W. if this is new code I would advice you to use mysqli instead of mysql.
Upvotes: 0
Reputation: 10040
while($row = mysql_fetch_assoc($result)) {
} or
while($row = mysql_fetch_array($result)) {
}
and mysql_ functions are depreciated now onwards in mysql
Upvotes: 0
Reputation: 2879
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
Upvotes: 1