/    Sign up×
Community /Pin to ProfileBookmark

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);[/CODE]

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++; } ?>[/CODE]

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

to post a comment
PHP

1 Comments(s)

×

Success!

Help @JS_Freak spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...