Jump to content

prob. dealing with while()


samoi

Recommended Posts

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

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 !

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.

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.