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
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!

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.