Jump to content

Google Charts, PHP and MYSQL


Xyn1407

Recommended Posts

Hello I have a project where there is data pulled in to a google image chart from a mysql database. The query is showing all the data that is supposed to be pulled in but the graph shows a straight line and is not showing all the data in the url from the query which you can see under url code.

 

This is the url that is posted after the query here

 

Here is the code that I am using to generate the chart

 

<?
$id_entity = $_product->getId();

$db_obj = mysql_connect('localhost', 'XXX', 'XXX');

mysql_select_db('data_base', $db_obj);

$query = "
SELECT 
a.frontend_label AS frontend_label,
b.value AS value
FROM eav_attribute AS a, catalog_product_entity_varchar AS b
WHERE a.attribute_id = b.attribute_id
&& b.entity_id = ".$id_entity."
&& a.attribute_id BETWEEN 564 AND 568
ORDER BY b.attribute_id ASC
";

$result = mysql_query($query);

$num_rows = mysql_num_rows($result);
        
    $array = array();
    
    $max = array();
    
    for($i = 0; $i < $num_rows; $i++) {
    
    	$row = mysql_fetch_object($result);
    	
    	$clean = str_replace(" ", '', $row->value);
    	
    	$explode = explode(',', $clean);
    	
    	$max[$i] = max($explode);
    	
    	$array[$i][0] = $row->frontend_label;
    	$array[$i][1] = $clean;
    	$array[$i][2] = str_replace(',', '|', $clean);
    	
    }

print_r($array);
    
?>

<img src="http://chart.apis.google.com/chart?cht=lc&chd=t:<?php echo $array[1][1]; ?>&chf=bg,s,FFFFFF&chxl=0:|<?php echo $array[0][2];?>|1:|<?php echo $array[1][2];?>|2:|<?php echo $array[2][2];?>&chs=500x250&chf=bg,s,FFFFFF&chco=FF0000&chxt=x,y,r">

 

Here is the array that is printed by the above code

 

Array ( [0] => Array ( [0] => RPM [1] => 2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000 [2] => 2000|2500|3000|3500|4000|4500|5000|5500|6000|6500|7000 ) [1] => Array ( [0] => Torque Before Tuning [1] => 200,300,315,320,400,500,400,390,370,360,350 [2] => 200|300|315|320|400|500|400|390|370|360|350 ) [2] => Array ( [0] => Horsepower Before Tuning [1] => 250,300,310,350,370,380,370,350,330,300,290 [2] => 250|300|310|350|370|380|370|350|330|300|290 ) [3] => Array ( [0] => Torque After Tuning [1] => 275,305,317,360,380,383,373,360,340,320,300 [2] => 275|305|317|360|380|383|373|360|340|320|300 ) [4] => Array ( [0] => Horsepower After Tuning [1] => 300,350,370,400,450,470,500,470,450,420,390 [2] => 300|350|370|400|450|470|500|470|450|420|390 ) ) 

 

Here is the url that is produced.

 

http://chart.apis.google.com/chart?cht=lc&chd=t:200,300,315,320,400,500,400,390,370,360,350&chf=bg,s,FFFFFF&chxl=0:|2000|2500|3000|3500|4000|4500|5000|5500|6000|6500|7000|1:|200|300|315|320|400|500|400|390|370|360|350|2:|250|300|310|350|370|380|370|350|330|300|290&chs=500x250&chf=bg,s,FFFFFF&chco=FF0000&chxt=x,y,r

 

I have been beating my head on my keyboard for days trying to figure out where I went wrong. Figured another set of eyes might help.

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.