Jump to content

[SOLVED] Displaying results in an array


Wildhalf

Recommended Posts

Hi All,

 

It's been a while since i played with PHP and i cant figure out how to fetch an entry in my MYSQL DB and display the results.

 

I thought something like the following would print out the username.

 

$result = mysql_query ("SELECT * FROM weight WHERE username='wildhalf'");
$data_result = mysql_fetch_array($result);

echo $data_result[username];

 

But how would i return all entries for a certain username, in the table and display them???

Link to comment
https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/
Share on other sites

<?php

$result = mysql_query("SELECT * FROM weight WHERE username = 'wildhalf'") or die(mysql_error());

while($date_result = mysql_fetch_assoc($result)) {
echo "{$data_result["username"]}<br />\n";
}

?>

 

That's the code.. seems pretty useless though as you know that all of the usernames will be 'wildhalf' due to your query!

Thats ok I was only testing. Will change the username onc ei have everything else working. My own code works and so does code i want to put together with it. But when combined everything goes pear shaped....

 

Going to try one more thing and then ill post all the code for your help...

corrected

<?php

$result = mysql_query("SELECT * FROM weight WHERE username = 'wildhalf'") or die(mysql_error());

while($data_result = mysql_fetch_assoc($result)) {
echo $data_result["username"];
}

?>

 

I already posted that more or less lol?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.