Wildhalf Posted December 20, 2007 Share Posted December 20, 2007 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??? Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/ Share on other sites More sharing options...
revraz Posted December 20, 2007 Share Posted December 20, 2007 http://us3.php.net/foreach Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419512 Share on other sites More sharing options...
chigley Posted December 20, 2007 Share Posted December 20, 2007 <?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! Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419513 Share on other sites More sharing options...
Wildhalf Posted December 20, 2007 Author Share Posted December 20, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419518 Share on other sites More sharing options...
redarrow Posted December 20, 2007 Share Posted December 20, 2007 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"]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419521 Share on other sites More sharing options...
chigley Posted December 20, 2007 Share Posted December 20, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419524 Share on other sites More sharing options...
redarrow Posted December 20, 2007 Share Posted December 20, 2007 your while loop says date_result not data_result in your first post Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419526 Share on other sites More sharing options...
chigley Posted December 20, 2007 Share Posted December 20, 2007 Whoopsies Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419528 Share on other sites More sharing options...
redarrow Posted December 20, 2007 Share Posted December 20, 2007 and from php 6 we dont use the curly brace we replace it with the [ ]ok.... Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419530 Share on other sites More sharing options...
chigley Posted December 20, 2007 Share Posted December 20, 2007 and from php 6 we dont use the curly brace we replace it with the [ ]ok.... I know.. but we're not on PHP6 yet, are we? Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419535 Share on other sites More sharing options...
redarrow Posted December 20, 2007 Share Posted December 20, 2007 you might not be but were very close, lots off pro bug php programmers are from the zend world lol..... apart from that the code is useless Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419538 Share on other sites More sharing options...
chigley Posted December 20, 2007 Share Posted December 20, 2007 I won't start using PHP6 until it's properly released. Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419541 Share on other sites More sharing options...
adam291086 Posted December 20, 2007 Share Posted December 20, 2007 hey guys if my host upgrades to php6 will all my code stop working? The current version of php i am using is php5 Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419544 Share on other sites More sharing options...
redarrow Posted December 20, 2007 Share Posted December 20, 2007 your lucky a host use the php 5 version php 6 on a host will take ages and your code will be fine.. Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419547 Share on other sites More sharing options...
adam291086 Posted December 20, 2007 Share Posted December 20, 2007 yeah but that day will eventually come. What then? Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419549 Share on other sites More sharing options...
Wildhalf Posted December 20, 2007 Author Share Posted December 20, 2007 Thanks all for your help. Got everything working fine now it is one great tool i found for drwing graphs from database using flash and php..... http://www.maani.us This will make the site im developing brilliant Quote Link to comment https://forums.phpfreaks.com/topic/82525-solved-displaying-results-in-an-array/#findComment-419561 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.