Hey everyone,
I have a SQL query that pulls data from my database:
[CODE]$sql = “SELECT Log_Date, Log_Reading, Channel, Device_Code, Zone_Code FROM datalog
WHERE Zone_Code = ‘”.$_REQUEST[‘zone’].”‘
AND Log_Date BETWEEN ‘”.$_REQUEST[‘day_from’].”‘ AND ‘”.$_REQUEST[‘day_to’].”‘
AND (Device_Code IN (SELECT Device_Code FROM devices WHERE Chan1_Reference='”.$_REQUEST[‘reference’].”‘) AND Channel=1)
OR (Device_Code IN (SELECT Device_Code FROM devices WHERE Chan2_Reference='”.$_REQUEST[‘reference’].”‘) AND Channel=2)
OR (Device_Code IN (SELECT Device_Code FROM devices WHERE Chan3_Reference='”.$_REQUEST[‘reference’].”‘) AND Channel=3)
OR (Device_Code IN (SELECT Device_Code FROM devices WHERE Chan4_Reference='”.$_REQUEST[‘reference’].”‘) AND Channel=4)
ORDER BY Channel, Log_Date”;
$result = mysql_query($sql);
I then use a while loop to grab this data and display it on my page:
[CODE] <?php
//$i = 0;
$prev = 0;
$first = true;
while ($rs = mysql_fetch_array($result)) {
?>
<tr <?php if (is_int($i/2)) print “bgcolor=”#A0D6F5″”; ?>>
<td height=”25″ style=”padding-left:5px; padding-right:2px;”><div class=”style1 style8″>
<?= ucwords($rs[“Log_Date”]); ?>
</div></td>
<td height=”25″ align=”center” style=”padding-left:5px; padding-right:2px;”><div class=”style1 style8″>
<?= ucwords($rs[“Channel”]); ?></div></td>
<td height=”25″ align=”center” class=”style1″ style=”padding-left:5px; padding-right:2px;”><span class=”style8″>
<?= ucwords($rs[“Zone_Code”]); ?>
</span> </td>
<td height=”25″ align=”center” class=”style1″ style=”padding-left:5px; padding-right:2px;”><div><span class=”style8″>
<?= ucwords($rs[“Device_Code”]); ?>
</span> </div></td>
<td height=”25″ align=”center” class=”style1″ style=”padding-left:5px; padding-right:2px;”><div><span class=”style8″>
<?
if ($rs2[‘Channel’] == ‘1’) {
$cur = $rs[“Log_Reading”] * $rs3[‘Chan1_Pulse_Weight’]; }
else if ($rs2[‘Channel’] == ‘2’) {
$cur = $rs[“Log_Reading”] * $rs3[‘Chan2_Pulse_Weight’]; }
else if ($rs2[‘Channel’] == ‘3’) {
$cur = $rs[“Log_Reading”] * $rs3[‘Chan3_Pulse_Weight’]; }
else if ($rs2[‘Channel’] == ‘4’) {
$cur = $rs[“Log_Reading”] * $rs3[‘Chan4_Pulse_Weight’]; }
echo $cur;
?>
</span> </div></td>
<td align=”center” class=”style1″ style=”padding-left:5px; padding-right:2px;”><div><span class=”style8″>
<?php
if ($first == true) {
$first = false;
echo “—-” ;
} else {
echo sprintf(“%.2f”, $cur – $prev);
}
$prev = $cur;
?>
</span></div></td>
</tr>
<?php $i++; } ?>
I took a screenshot of the resultant data that gets displayed on the page. It’s the jpeg attached to this post.
My question, how do I display this data from my while loop in graph format?
Thanks!
Karen