3

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

3 Answers 3

1
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

Sign up to request clarification or add additional context in comments.

Comments

0
while($row = mysql_fetch_assoc($result)) { 
} or
while($row = mysql_fetch_array($result)) { 
}

and mysql_ functions are depreciated now onwards in mysql

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.