Jump to content

help with array/loop?


Recommended Posts



I am trying to tidy up a bit of php code to make the end display much better but I am a bit stuck, I have the following code which takes a mysql query and uses the result to create a google graph.


$str = "";
  $str .=  "<img src='http://chart.apis.google.com/chart?chs=600x300";
  $str .= "&chd=t:"; 

while($row_Recordset3 = mysql_fetch_assoc($Recordset3)){
$reading_array[$i] = $row_Recordset3['reading'];
$date_array[$i] = date("j/n", strtotime($row_Recordset3['date']));
$i ++;
$count = count($reading_array);
if($count>1) {
$rstring = implode(",", (array_reverse($reading_array)));
$dstring = implode("|", (array_reverse($date_array)));
echo $count;

$str = $str.$rstring;

  $str = $str."&cht=lc&chxl=0:|";
  // We will close the src attribute with \' and to print escape character ' we shall precede it with \

$str = $str.$dstring;

  $str = $str."&chxt=x,y&chds=0,25&chxr=1,0,25,5&chm=o,0044FF,0,-1,8|b,3399CC44,0,1,0&chtt=Electricity Generation for the last 35 days'";
  $str = $str." >";

  //we shall echo the $str that will display the graph
  echo $str;


Currently the result is



I need to make it display only every 7 dates so that they are readable but I still need the pipes in between to space out the dates correctly so they tie in with the correct point on the graph, like this where I manually removed some dates as a demo



This is beyond my limited stills, can anyone help please?





Link to comment
Share on other sites


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.