SMPoint Posted February 17, 2009 Share Posted February 17, 2009 Hello all, Kind of stumped and am looking for some guidance. I have data that I grab "mysql_fetch_array" and it displays the results as expected. One by one, the "job" displays with all of the data for that day. The problem is I would like to group the data by day on the page so if I run a query of more than 1 day, I can take the multiple day results and display them properly. I am unfamiliar with displaying grouped data in a single page. Can someone point me in the right dir? This might help.... $sql = "SELECT * from XXX where start_search BETWEEN '$nowq_date' AND '$nowq5_date' ORDER BY start_search ASC"; $result = mysql_query($sql,$connection) or die("Invalid query: " . mysql_error()); while ($row = mysql_fetch_array($result)) { $start = $row["start"]; $end = $row["end"]; $date = $row["date"]; echo "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='4'><TR> <TD WIDTH='25%' NOWRAP>$date</TD> <TD WIDTH='20%'>$start</TD> <TD WIDTH='15%'>$end</TD> </TR></TABLE>"; } This prints .... 02/12/2009 start1 end1 02/12/2009 start2 end2 02/12/2009 start3 end3 02/13/2009 start1 end1 02/13/2009 start2 end2 02/14/2009 start3 end3 But I want it to print ... 02/12/2009 start1 end1 02/12/2009 start2 end2 02/12/2009 start3 end3 SPACE HERE 02/13/2009 start1 end1 02/13/2009 start2 end2 SPACE HERE 02/14/2009 start3 end3 Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/ Share on other sites More sharing options...
mrdamien Posted February 17, 2009 Share Posted February 17, 2009 $sql = "SELECT * from XXX where start_search BETWEEN '$nowq_date' AND '$nowq5_date' ORDER BY start_search ASC"; $result = mysql_query($sql,$connection) or die("Invalid query: " . mysql_error()); $previous_date = 0; while ($row = mysql_fetch_array($result)) { $start = $row["start"]; $end = $row["end"]; $date = $row["date"]; if($previous_date === 0){ $previous_date = $date; }else if($date != $previous_date){ $previous_date = $date; echo "<br>"; // extra space } echo "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='4'><TR> <TD WIDTH='25%' NOWRAP>$date</TD> <TD WIDTH='20%'>$start</TD> <TD WIDTH='15%'>$end</TD> </TR></TABLE>"; } Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/#findComment-763997 Share on other sites More sharing options...
SMPoint Posted February 17, 2009 Author Share Posted February 17, 2009 Well, it worked out great. I am totally confused, but only because I did not know what "===" was. I thought it was a typo. I was unaware of indentity array operators. I have used all of the others thousands of times, but never seen those. Were those always around in older versions of PHP? Anyways, thanks a million!! Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/#findComment-764024 Share on other sites More sharing options...
SMPoint Posted February 18, 2009 Author Share Posted February 18, 2009 Ok, well I thought I had it, but I do not. I was taking the premise of the code that mrdamien gave me and thought I could use it the same way. Instead of using it for spacing...<BR><BR>...I though I would throw in an include file that displays a top of a box and then I wanted to throw in a footer that would display the bottom of the box...wrap the results by day using some graphics. Here is the modified code... $sql = "SELECT * from XXX where start_search BETWEEN '$nowq_date' AND '$nowq5_date' ORDER BY start_search ASC"; $result = mysql_query($sql,$connection) or die("Invalid query: " . mysql_error()); $previous_date = 0; while ($row = mysql_fetch_array($result)) { $start = $row["start"]; $end = $row["end"]; $date = $row["date"]; if($previous_date === 0){ $previous_date = $date; }else if($date != $previous_date){ $previous_date = $date; include ("header.php"); } echo "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='4'><TR> <TD WIDTH='25%' NOWRAP>$date</TD> <TD WIDTH='20%'>$start</TD> <TD WIDTH='15%'>$end</TD> </TR></TABLE>"; } My question is, where do I put the code to properly wrap the footer data by date using an include file? Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/#findComment-764838 Share on other sites More sharing options...
mrdamien Posted February 18, 2009 Share Posted February 18, 2009 while ($row = mysql_fetch_array($result)) { $start = $row["start"]; $end = $row["end"]; $date = $row["date"]; if($previous_date === 0){ $previous_date = $date; }else if($date != $previous_date){ include ("header.php"); } echo "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='4'><TR> <TD WIDTH='25%' NOWRAP>$date</TD> <TD WIDTH='20%'>$start</TD> <TD WIDTH='15%'>$end</TD> </TR></TABLE>"; if($date != $previous_date){ $previous_date = $date; include ("footer.php"); } } I think this is what you want... Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/#findComment-764839 Share on other sites More sharing options...
SMPoint Posted February 18, 2009 Author Share Posted February 18, 2009 It did not work so I just did the include in the same section as your modified code... if($date != $previous_date){ $previous_date = $date; include ("footer.php"); } changed to include ("footer.php"); and it includes the footer, but only the first result of each day is wrapped, not all of the data of each day. Does that help? Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/#findComment-764859 Share on other sites More sharing options...
SMPoint Posted February 18, 2009 Author Share Posted February 18, 2009 $sql = "SELECT * from XXX where start_search BETWEEN '$nowq_date' AND '$nowq5_date' ORDER BY start_search ASC"; $result = mysql_query($sql,$connection) or die("Invalid query: " . mysql_error()); if (mysql_num_rows ($result) == 0){ echo "blah"; } $group_date = 0; while ($row = mysql_fetch_array($result)) { $start = $row["start"]; $end = $row["end"]; $date = $row["date"]; if($group_date === 0){ $group_date = $date; } else if($date != $group_date){ $group_date = $date; include ("includes/header_pop_group.php"); } echo "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='3'> <TR> <TD WIDTH='25%' BACKGROUND='images/group-blue-02.gif' HEIGHT='15'><B>XXX</B></TD> <TD WIDTH='25%' BACKGROUND='images/group-blue-02.gif' HEIGHT='15'><B>ZZZ</B></TD> <TD WIDTH='25%' BACKGROUND='images/group-blue-02.gif' HEIGHT='15'><B>YYY</B></TD> </TR> <TR> <TD WIDTH='25%' VALIGN='TOP'>$date</TD> <TD WIDTH='25%' VALIGN='TOP'>$start</TD> <TD WIDTH='25%' VALIGN='TOP'>$end</TD> </TR></TABLE>"; include ("includes/footer_pop.php"); } The above code prints each result per day like this... 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data header wrapped 02/13/2009 data data footer wrapped 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data header wrapped 02/14/2009 data data footer wrapped 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data and I want it to go like this... header wrapped 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data 02/12/2009 data data footer wrapped header wrapped 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data 02/13/2009 data data footer wrapped header wrapped 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data 02/14/2009 data data footer wrapped Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/#findComment-764864 Share on other sites More sharing options...
sasa Posted February 18, 2009 Share Posted February 18, 2009 try <?php $sql = "SELECT * from XXX where start_search BETWEEN '$nowq_date' AND '$nowq5_date' ORDER BY start_search ASC"; $result = mysql_query($sql,$connection) or die("Invalid query: " . mysql_error()); $previous_date = 0; while ($row = mysql_fetch_array($result)) { $start = $row["start"]; $end = $row["end"]; $date = $row["date"]; if($previous_date === 0){ $previous_date = $date; include ("header.php"); }else if($date != $previous_date){ $previous_date = $date; include ("footer.php"); include ("header.php"); } echo "<TABLE WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='4'><TR> <TD WIDTH='25%' NOWRAP>$date</TD> <TD WIDTH='20%'>$start</TD> <TD WIDTH='15%'>$end</TD> </TR></TABLE>"; } include ("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/#findComment-764916 Share on other sites More sharing options...
SMPoint Posted February 18, 2009 Author Share Posted February 18, 2009 When I saw include ("footer.php"); include ("header.php"); It totally clicked. I never thought to run the footer then the header right under. I was looking to run header and somewhere else to run footer. Thanks to both sasa and mrdamien for being that extra set of eyes. This helped tremendously. Quote Link to comment https://forums.phpfreaks.com/topic/145510-solved-displaying-dates-with-multiple-rows-grouped-together/#findComment-765002 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.