I am trying to setup an application availability report, I have an array of with app names in it and a number. I am going through the list and finding the duration of issues for each one and saving it a corresponding array and then doing a calculation on it. I try to print it out to a table but no dice. I have my test echos and for loops still in there and I get a the app array printed out but inside the while look doesn't execute and I can't pinpoint why. Thanks for the help and I can answer questions about it. I am going to put a month/year form input at the bottom with a submit button that calls this same page back.
<?php
$applist = array('default1','default2','default3');
$numofapps = 3;
$i=0;
$downtime;
if($_POST['submitted']==1)
{
$month = $_POST['startmonth'];
}
else {
$month = date("m");
}
echo "<br />";
switch ($month){
case 01:
case 03:
case 05:
case 07:
case 08:
case 10:
case 12:
$totaltime = 31 * 1440;
break;
case 04:
case 06:
case 09:
case 11:
$totaltime = 30 * 1440.0;
break;
case 02:
$year = $_POST['startyear'];
if(($year%4)==0)
{
$totaltime = 29 * 1440.0;
}
else {
$totaltime = 28 * 1440.0;
}
break;
}
echo "<br />";
while($numofapps > $i)
{
$query="Select `duration` from `issuetrack` WHERE `app`='" . $applist[$i] . "'";
$result=mysql_query($query);
while($row = mysql_fetch_array($result))
{
echo $downtime[$i];
echo "TEST downtime <br />";
echo $row[$i];
echo "ETST DURATION <br />";
$downtime[$i]+=$row['duration'];
}
$appavail[$i]=($downtime[$i] / $totaltime) * 100;
$i++;
echo "<br />";
}
$j=0;
echo "<table border ='1'>";
echo "<tr><th>Application Affected</th><th>Application Availability</th>";
while ($numofapps > $j)
{
echo "<tr><td>";
echo $applist[$i];
echo "</td><td>";
echo $appavail[$i];
echo "</td></tr>";
}
echo "</table>";
?>
Check the $result variable like,
if($result)
echo "1";
else
echo mysql_error();
Even if you don't have any data, if your query is right then it prints 1, otherwise it prints error if any.
Also check your mysql_connection to find out you've a connection to db, like this:
mysql_connect('localhost','username','password') or die (mysql_error());
If your script isn't entering while($row = mysql_fetch_array($result))
then it's because the query didn't return any results. Try printing out your query ( echo $query
) and run it directly in mysql to see what it gives back.
The variables in the while ($numofapps > $j)
loop are indexed by $i but they should be indexed by $j. Also, you need a $j++ there or it will loop until the script execution time limit is reached.
as a first step check the mysql connection
mysql_connect('localhost','username','password') or die (mysql_error());
if there is connection then check the query is returning something by using the following query
$count=mysql_num_rows($result);
if($count!=0)
{
while($row = mysql_fetch_array($result))
{
echo $downtime[$i];
echo "TEST downtime <br />";
echo $row[$i];
echo "ETST DURATION <br />";
$downtime[$i]+=$row['duration'];
}
}
else
{
echo "The query returned empty";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.