Click to See Complete Forum and Search --> : Table---- It's urgent


rashmi_k28
03-31-2008, 11:11 PM
Suppose I have 3 dates and rows fetched from table should be displayed in 3 separate table for each date.

But table displaying now doesnot show the rows for that particular date in table.

Table is divided into 3 but first table shows the rows which contains date as on '2008-03-18' and second table shows 18th and 19th dates rows and third table contains all the rows fetched from the table.


How to display rows based on date in particular table




$start_date='2008-03-18';
$end_date='2008-03-20';


$res_date=mysql_query("select distinct(date(timestamp)) from `table` where date(timestamp)>= '".$start_date."' and date(timestamp) <= '".$end_date."'");

while($res2=mysql_fetch_array($res_date)){


while($result = mysql_fetch_array($row))
{

$sql_ip="select ip from `table_name` where head_node='".$res[0]."'";
$sql_ip1=mysql_query($sql_ip);
while($ip=mysql_fetch_array($sql_ip1)){

$currentStatus = $result['status'];
$currentTime = $result['timestamp'];
$previousStatus = $previousStatus == '' ? $currentStatus : $previousStatus;
$previoustime = $previoustime == '' ? $currentTime : $previoustime;

if($previousStatus <> $currentStatus)
{
$d = strtotime($currentTime) - strtotime($previoustime);
array_push($records,"$result[2]#$ip[0]#$result[2]#$previoustime#$result[1]#$d");

}
$previousStatus = $currentStatus;
}
}

echo "<html>";
echo "<head>";
echo "<TABLE BORDER=2 CELLPADDING=4 width=\"100%\" bordercolor=\"#000000\"><TR><TH COLSPAN=2>DATE AS ON $res2[0]</TH><th COLSPAN=6>Status(Down)</th></TR><TR><TH COLSPAN=8>NETWORK</TH></TR><TR><TD>SL NO</TD><TD>NAME</TD><TD>IP </TD><TD>NAME</TD><TD>START TIME</TD><TD>END TIME</TD><TD>DURATION in (days:hours:minutes)</TD></TR>";
$x=count($records);
for($i=0;$i<count($records);$i++){
$data=split("#",$records[$i]);
$seconds=$data[5];
$hours = floor($seconds/3600);
$days=floor($hours/24);
$hoursleft= $hours%24;
$timeleft = $seconds - ($hours*3600);
$minutes = floor($timeleft/60);
$seconds = $timeleft - ($minutes*60);


echo "<tr>";
echo "<td>".($i+1)."</td>";
echo "<td>$data[0]</td>";
echo "<td>$data[1]</td>";
echo "<td>$data[2]</td>";
echo "<td>$data[3]</td>";
echo "<td>$data[4]</td>";
echo "<td>$days:$hoursleft:$minutes</td>";
}
echo "</tr><br><br></table>";
}


echo "</body></html>";

rashmi_k28
04-02-2008, 01:56 AM
Anyone please help me with this.

shankshang
04-02-2008, 03:25 AM
Hi there,

I guess I can give a try to solve your problem if you could just paste the value (array value) that is stored in "$records".

i.e, could you please give the print_r($records); just before
echo "<html>"; and copy paste the value printed for that array so that would make it easy for me to fix.

regards,
Shankar
02 Apr 08

shankshang
04-02-2008, 03:33 AM
$start_date='2008-03-18';
$end_date='2008-03-20';
$records = array ();

$res_date=mysql_query("select distinct(date(timestamp)) from `table` where date(timestamp)>= '".$start_date."' and date(timestamp) <= '".$end_date."'");

while($res2=mysql_fetch_array($res_date)) {
while($result = mysql_fetch_array($row))
{
$sql_ip="select ip from `table_name` where head_node='".$res[0]."'";
$sql_ip1=mysql_query($sql_ip);
while($ip=mysql_fetch_array($sql_ip1)) {
$currentStatus = $result['status'];
$currentTime = $result['timestamp'];
$previousStatus = $previousStatus == '' ? $currentStatus : $previousStatus;
$previoustime = $previoustime == '' ? $currentTime : $previoustime;

if($previousStatus <> $currentStatus) {
$d = strtotime($currentTime) - strtotime($previoustime);
array_push($records,"$result[2]#$ip[0]#$result[2]#$previoustime#$result[1]#$d");
}
$previousStatus = $currentStatus;
}
}
}

echo "<html>";
echo "<head>";
echo "<TABLE BORDER=2 CELLPADDING=4 width=\"100%\" bordercolor=\"#000000\"><TR><TH COLSPAN=2>DATE AS ON $res2[0]</TH><th COLSPAN=6>Status(Down)</th></TR><TR><TH COLSPAN=8>NETWORK</TH></TR><TR><TD>SL NO</TD><TD>NAME</TD><TD>IP </TD><TD>NAME</TD><TD>START TIME</TD><TD>END TIME</TD><TD>DURATION in (days:hours:minutes)</TD></TR>";
$x=count($records);
for($i=0;$i<count($records);$i++) {
$data=split("#",$records[$i]);
$seconds=$data[5];
$hours = floor($seconds/3600);
$days=floor($hours/24);
$hoursleft= $hours%24;
$timeleft = $seconds - ($hours*3600);
$minutes = floor($timeleft/60);
$seconds = $timeleft - ($minutes*60);

echo "<tr>";
echo "<td>".($i+1)."</td>";
echo "<td>$data[0]</td>";
echo "<td>$data[1]</td>";
echo "<td>$data[2]</td>";
echo "<td>$data[3]</td>";
echo "<td>$data[4]</td>";
echo "<td>$days:$hoursleft:$minutes</td>";
}
echo "</tr><br><br></table>";
echo "</body></html>";

rashmi_k28
04-02-2008, 03:46 AM
master##master#2008-03-18 00:40:01#2008-03-18 00:50:01#600master.in#192.192.192.1#master.in#2008-03-18 19:50:01#2008-03-18 20:00:01#600n24#172.0.0.0#n24#2008-03-18 06:50:01#2008-03-18 09:40:01#10200n24#172.0.0.0#n24#2008-03-18 09:40:01#2008-03-18 09:50:01#600c01#10.0.0.0#c01#2008-03-18 13:20:02#2008-03-18 13:30:01#599c01#10.0.0.0#c01#2008-03-18 13:30:01#2008-03-18 13:40:02#601c01#10.0.0.0#c01#2008-03-18 19:30:01#2008-03-18 19:40:01#600c01#10.0.0.0#c01#2008-03-18 19:40:01#2008-03-18 19:50:01#600master.in#192.0.0.0#master.in#2008-03-19 04:20:01#2008-03-19 04:30:01#600master.jnu.ac.in#192.0.0.0#master.in#2008-03-19 04:30:01#2008-03-19 04:40:01#600master.in#192.0.0.0#master.in#2008-03-19 11:30:01#2008-03-19 11:40:01#600master.in#192.0.0.0#master.in#2008-03-19 11:40:01#2008-03-19 11:50:01#600master.in#192.0.0.0#master.in#2008-03-19 12:00:01#2008-03-19 12:10:01#600master.in#192.0.0.0#master.in#2008-03-19 12:10:01#2008-03-19 12:20:01#600master.in#192.0.0.0#master.in#2008-03-20 01:50:01#2008-03-20 02:00:02#601master.in#192.0.0.0#master.in#2008-03-20 02:00:02#2008-03-20 02:10:01#599master##master#2008-03-20 03:00:02#2008-03-20 03:10:01#599master##master#2008-03-20 03:10:01#2008-03-20 03:20:02#601


print_r($records) is as above.

Please help me to solve it

shank
04-02-2008, 06:15 AM
Hi, its me again "shankshang", sorry for the late reply as I forgot my password and had to create a new id :D

the array value cannot be used as it comes inside the while loop which connects to the DB each time it enters the loop

I suggest, can you please go through my second reply? or copy paste this code and test?, let me know if it works


$start_date='2008-03-18';
$end_date='2008-03-20';
$records = array ();

$res_date=mysql_query("select distinct(date(timestamp)) from `table` where date(timestamp)>= '".$start_date."' and date(timestamp) <= '".$end_date."'");

while($res2=mysql_fetch_array($res_date)) {
while($result = mysql_fetch_array($row))
{
$sql_ip="select ip from `table_name` where head_node='".$res[0]."'";
$sql_ip1=mysql_query($sql_ip);
while($ip=mysql_fetch_array($sql_ip1)) {
$currentStatus = $result['status'];
$currentTime = $result['timestamp'];
$previousStatus = $previousStatus == '' ? $currentStatus : $previousStatus;
$previoustime = $previoustime == '' ? $currentTime : $previoustime;

if($previousStatus <> $currentStatus) {
$d = strtotime($currentTime) - strtotime($previoustime);
array_push($records,"$result[2]#$ip[0]#$result[2]#$previoustime#$result[1]#$d");
}
$previousStatus = $currentStatus;
}
}
}

echo "<html>";
echo "<head>";
echo "<TABLE BORDER=2 CELLPADDING=4 width=\"100%\" bordercolor=\"#000000\"><TR><TH COLSPAN=2>DATE AS ON $res2[0]</TH><th COLSPAN=6>Status(Down)</th></TR><TR><TH COLSPAN=8>NETWORK</TH></TR><TR><TD>SL NO</TD><TD>NAME</TD><TD>IP </TD><TD>NAME</TD><TD>START TIME</TD><TD>END TIME</TD><TD>DURATION in (days:hours:minutes)</TD></TR>";
$x=count($records);
for($i=0;$i<count($records);$i++) {
$data=split("#",$records[$i]);
$seconds=$data[5];
$hours = floor($seconds/3600);
$days=floor($hours/24);
$hoursleft= $hours%24;
$timeleft = $seconds - ($hours*3600);
$minutes = floor($timeleft/60);
$seconds = $timeleft - ($minutes*60);

echo "<tr>";
echo "<td>".($i+1)."</td>";
echo "<td>$data[0]</td>";
echo "<td>$data[1]</td>";
echo "<td>$data[2]</td>";
echo "<td>$data[3]</td>";
echo "<td>$data[4]</td>";
echo "<td>$days:$hoursleft:$minutes</td>";
}
echo "</tr><br><br></table>";
echo "</body></html>";

bathurst_guy
04-02-2008, 06:23 AM
(sorry to post this in the forum but PM's haven't yet activated for the user)
shank, it is against forum policy to have more than one user account. You can retrieve/reset your forgotten password by having an email sent to your confirmed address. Please let me know which account you want to keep and which to delete so it can be done.

shank
04-02-2008, 06:32 AM
Please retain my id "shank" and delete the other "shankshang", thanks...

bathurst_guy
04-02-2008, 06:39 AM
Thanks. Done.

rashmi_k28
04-02-2008, 06:42 AM
Hi Shank,


The code is not working as all the rows fetched is in single table. The table is not divided based on date.

The previous code which I had was
table 1 had contained rows which of date 18th
table 2 had contained rows of date 18th and 19th
table3 had contained all the rows of date 18th ,19th and 20th

shank
04-02-2008, 07:15 AM
Hi... I am not sure if this will solve, but again you can give a try...
I get a feeling that the array is not flushed before again pushing the elements into that.. so give a try this way...
have the array reset just after or before the end of table tag....

echo "</tr><br><br></table>";
$records = array ();

rashmi_k28
04-03-2008, 03:08 AM
thanks for the reply. It worked