samoi Posted April 5, 2009 Share Posted April 5, 2009 Hi everything is in the code <?php /** * connection to db; * * selecting db * $SQL = "SELECT * from soldiers WHERE species = 1"; $mSQL = mysql_query($SQL); * */ # my chart while($data = mysql_fetch_assoc($mSQL)) { $data['name'] = $chart['name']; // every soldier has a name $data['attack'] = $chart['attack']; // every soldier has an attack power } $chart['name'] = $chart['attack']; // here the chart values takes place for example # $chart['john'] = 507 # outputs John 507 in the chart ! ######################################### # # # while statement cannot handle it! WHY?# # # ######################################### $mc4 = new maxChart($chart); $mc4->displayChart('My Chart', 0, 500, 150, true); ?> Thanks in adv. Link to comment https://forums.phpfreaks.com/topic/152626-prob-dealing-with-while/ Share on other sites More sharing options...
xtopolis Posted April 5, 2009 Share Posted April 5, 2009 What's your question? You're not doing anything significant in your while loop? It looks like you're overwriting the values for the whole of the result set. Link to comment https://forums.phpfreaks.com/topic/152626-prob-dealing-with-while/#findComment-801563 Share on other sites More sharing options...
samoi Posted April 5, 2009 Author Share Posted April 5, 2009 What's your question? You're not doing anything significant in your while loop? It looks like you're overwriting the values for the whole of the result set. Thanks for answering But what I really want is end up with values like $chart['john'] = 507; $chart['sam'] = 400; $chart['jean'] = 200; $chart['rose'] = 146; of course I need them to be from the loop statement! but when I do that code, it goesn't work ! Link to comment https://forums.phpfreaks.com/topic/152626-prob-dealing-with-while/#findComment-801565 Share on other sites More sharing options...
thebadbad Posted April 5, 2009 Share Posted April 5, 2009 I think this is what you're looking for: <?php $chart = array(); while ($data = mysql_fetch_assoc($mSQL)) { $chart[$data['name']] = $data['attack']; } ?> Of course only works if the fields in your DB is called name and attack. Edit: Had a syntax error. Link to comment https://forums.phpfreaks.com/topic/152626-prob-dealing-with-while/#findComment-801571 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.