Jump to content

help with array/loop?


ruraldev

Recommended Posts

Hi

 

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.

 

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


$i=0;
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=0;
$count = count($reading_array);
if($count>1) {
$rstring = implode(",", (array_reverse($reading_array)));
$dstring = implode("|", (array_reverse($date_array)));
}else{
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
  ?>
  <tr><td>
  <?php
  echo $str;
?>

 

Currently the result is

http://chart.apis.google.com/chart?chs=600x300&chd=t:10,6,1,11,12,7,6,2,1,1,4,10,1,5,12,3,3,6,1,6,3,3,1,5,3,1,1,6,8,5,8,8&cht=lc&chxl=0:|27/10|28/10|29/10|30/10|31/10|1/11|2/11|3/11|4/11|5/11|6/11|7/11|8/11|9/11|10/11|11/11|12/11|13/11|14/11|15/11|16/11|17/11|18/11|19/11|20/11|21/11|22/11|23/11|24/11|25/11|26/11|27/11&chxt=x,y&chds=0,25&chxr=1,0,25,5&chm=o,0044FF,0,-1,8|b,3399CC44,0,1,0&chtt=Electricity%20Generation%20for%20the%20last%2035%20days

 

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

http://chart.apis.google.com/chart?chs=600x300&chd=t:10,6,1,11,12,7,6,2,1,1,4,10,1,5,12,3,3,6,1,6,3,3,1,5,3,1,1,6,8,5,8,8&cht=lc&chxl=0:|27/10|||||1/11|||||6/11|7/11|8/11|9/11|10/11|11/11|12/11|13/11|14/11|15/11|16/11|17/11|18/11|19/11|20/11|21/11|22/11|23/11|24/11|25/11|26/11|27/11&chxt=x,y&chds=0,25&chxr=1,0,25,5&chm=o,0044FF,0,-1,8|b,3399CC44,0,1,0&chtt=Electricity%20Generation%20for%20the%20last%2035%20days

 

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

 

Thanks

 

Gordon

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.