Customizing SMF > SMF Coding Discussion

Custom script uptime problem :/

(1/1)

MoneyMan87:
can someone tell me what is the problem with this script :(

--- Code: ---<?
$sid = $_SESSION['id'];

$q = 'select name from s_servers where id='.$sid;
//echo $q;
$result = mysql_query($q);
while ($row = mysql_fetch_array($result))
{
$numserver = $row[name];
  $id_serv = $row[id];
}

$q = 'select status, date(date_added) as data_add from stats where srv_id='.$sid.' and day(date_added) in (day(now()-interval 1 day),day(now()-interval 2 day),day(now()-interval 3 day),day(now()-interval 4 day),day(now()-interval 5 day)) order by date_added desc';
$result = mysql_query($q);
$nr = 0;
{
if (!isset($vect[$row[data_add]]))
{
$nr++;
$index[$nr]=$row[data_add];
$vect[$row[data_add]]=1;
$vect_nr[$row[data_add]] = $row[status];
}
else
{
$vect[$row[data_add]]++;
$vect_nr[$row[data_add]]+=$row[status];
}
}

for ($i=1;$i<6;$i++)
{
if (isset($index[$i]))
$procent[$i] = round(($vect_nr[$index[$i]]*200)/($vect[$index[$i]]));
else
$procent[$i]=0;
}

echo '

<object width="500" height="150" id="myNext" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0&quot;" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
<param value="always" name="allowScriptAccess">
<param value="" name="movie">
<param value="&amp;chartWidth=500&amp;chartHeight=150&amp;dataXML=&lt;graph caption=\'5 days uptime for '.$numserver.'\' xAxisName=\'\' yAxisName=\'Uptime\' decimalPrecision=\'0\' formatNumberScale=\'0\' numberSuffix=\'%25 \' canvasBorderColor=\'DAE1E8\' bgcolor=\'e9e9e9\'&gt;&lt;set name=\'yesterday\' value=\''.round($procent[1]/2).'\' color=\'#006600\' /&gt;&lt;set name=\'2 days ago\' value=\''.round($procent[2]/2).'\' color=\'#006600\' /&gt;&lt;set name=\'3 days ago\' value=\''.round($procent[3]/2).'\' color=\'#006600\' /&gt;&lt;set name=\'4 days ago\' value=\''.round($procent[4]/2).'\' color=\'#006600\'/&gt;&lt;set name=\'5 days ago\' value=\''.round($procent[5]/2).'\' color=\'#006600\'/&gt;&lt;/graph&gt;" name="FlashVars">
<param value="high" name="quality">
<embed width="500" height="150" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="always" name="myNext" quality="high" flashvars="&amp;chartWidth=500&amp;chartHeight=150&amp;dataXML=&lt;graph caption=\'5 days uptime for '.$numserver.'\' xAxisName=\'\' yAxisName=\'L2VoteZone.com Uptime\' decimalPrecision=\'0\' formatNumberScale=\'0\' numberSuffix=\'%25 \' canvasBorderColor=\'DAE1E8\' bgcolor=\'e9e9e9\'&gt;&lt;set name=\'yesterday\' value=\''.round($procent[1]/2).'\' color=\'#006600\' /&gt;&lt;set name=\'2 days ago\' value=\''.round($procent[2]/2).'\' color=\'#006600\' /&gt;&lt;set name=\'3 days ago\' value=\''.round($procent[3]/2).'\' color=\'#006600\' /&gt;&lt;set name=\'4 days ago\' value=\''.round($procent[4]/2).'\' color=\'#006600\'/&gt;&lt;set name=\'5 days ago\' value=\''.round($procent[5]/2).'\' color=\'#006600\'/&gt;&lt;/graph&gt;" src="http://L2VoteZone.com/js/FCF_Column2D.swf">
</object>
<br />
';

?>
--- End code ---
The live scriot is here: http://l2votezone.com/sinfo/270.html  and press down uptime :) but for other site works perfect but i don't know what they have do :( like this  http://i-top.in/sinfo/1.html

Shambles:
Hi moneyman

As you've had no replies yet I figured I'd draw some flack by posting my thoughts.

(I'm no php coder, though I've been messing around for a short while and trying to learn some stuff)

The first thing that springs to mind is the use of $row outside of the "while ($row = mysql_fetch_array($result))" loop; will $row still be in scope outside that construct? You seem to rely on it later on.

Next, again forgive me if I'm wrong, but don't array keys need to be in quotes if they're literal names, like $row['name']?

Ah well, at least you got a reply.

Sorck:
Shambles is right in that you need your array key's need to have quotation marks around them. However, PHP will simply be filling up your error log and treating your constants as if they were strings.

Your problem is your lack of actually fetching the data from the second query I'd think - mysql_fetch_assoc( $resource ) is your friend here. :)

$row will still be defined after the first while() loop. While doesn't change the variable scope.

Navigation

[0] Message Index

Go to full version