Jump to content

Array Help


e1seix

Recommended Posts

Hello hello.

 

Have been searching for a pie chart script to use, which I have now found. However the code requires the following data:

 

$data = array(
		'IE7' => 22,
		'IE6' => 30.7,
		'IE5' => 1.7,
		'Firefox' => 36.5,
		'Mozilla' => 1.1,
		'Safari' => 2,
		'Opera' => 1.4,
	);

 

My issue is that I have the name (ie. IE6) and percentage value (ie. 30.7) stored in a mysql database. How can I translate it to the array with the help of an sql statement to list each individual table entry and their respective percentage value?

 

EG.

 

      $query = 'SELECT * FROM list WHERE percentage > "0.00"';
      $results = mysql_query( $query ) or die( mysql_error() );
       while( $row = mysql_fetch_array( $results ) ) { ... <etc.>

echo $row["name"];
echo $row["percentage"]; ... }
[/code[

Many thanks.

Link to comment
https://forums.phpfreaks.com/topic/210257-array-help/
Share on other sites

 $query = 'SELECT * FROM list WHERE percentage > "0.00"';
      $results = mysql_query( $query ) or die( mysql_error() );
       while( $row = mysql_fetch_array( $results ) ) { ... <etc.>

echo $row["name"];
echo $row["percentage"]; 
$data[$row["name"]] = $row["percentage"];
}

Link to comment
https://forums.phpfreaks.com/topic/210257-array-help/#findComment-1097250
Share on other sites

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.