mishasoni Posted December 5, 2008 Share Posted December 5, 2008 I am a PHP noob and have been unable to find a solution for the following: I am working with a mySQL table called "Agenda" with the following columns: Date, Time, TalkTitle, Talk_ID. I need to display this on a page so that it reads as a normal agenda, like this: Day 1 8:00a talk 1.1 title 10:00a talk 1.2 title 12:00p talk 1.3 title Day 2 8:30a talk 2.1 title 11:00a talk 2.2 title 1:00p talk 2.3 title Day 3 8:00a talk 3.1 title 9:00a talk 3.2 title 12:30p talk 3.3 title (this is a simplified example just to illustrate what I am trying to achieve) Unfortunately my current code produces this (using a nested loop): Day 1 8:00a talk 1.1 title Day 1 10:00a talk 1.2 title Day 1 12:00p talk 1.3 title Day 2 8:30a talk 2.1 title Day 2 11:00a talk 2.2 title ...etc... Can anyone walk me through the basics of displaying data in the manner intended? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/135712-nested-loop-for-displaying-agendacalendar-info/ Share on other sites More sharing options...
premiso Posted December 5, 2008 Share Posted December 5, 2008 Post some code. Chances are it is your loop that is the problem, move the day definition so it is not printing every time the loop is ran, only when it is needed to be printed. Quote Link to comment https://forums.phpfreaks.com/topic/135712-nested-loop-for-displaying-agendacalendar-info/#findComment-707092 Share on other sites More sharing options...
mishasoni Posted December 5, 2008 Author Share Posted December 5, 2008 Here's my code: <?php $colname_master1Agenda = "-1"; if (isset($_GET['recordID'])) { $colname_master1Agenda = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_AGCI, $AGCI); $query_master1Agenda = sprintf("SELECT * Agenda WHERE EventID_fk = %s ORDER BY Date", GetSQLValueString($colname_master1Agenda, "int")); $master1Agenda = mysql_query($query_master1Agenda, $AGCI) or die(mysql_error()); $row_master1Agenda = mysql_fetch_assoc($master1Agenda); $totalRows_master1Agenda = mysql_num_rows($master1Agenda); mysql_select_db($database_AGCI, $AGCI); $query_detail2Agenda = "SELECT * FROM Agenda WHERE Talk_ID=123456789 ORDER BY Time ASC"; $detail2Agenda = mysql_query($query_detail2Agenda, $AGCI) or die(mysql_error()); $row_detail2Agenda = mysql_fetch_assoc($detail2Agenda); $totalRows_detail2Agenda = mysql_num_rows($detail2Agenda); ?> <div id="agenda"> <table border="0"> <tr class="faint_gray"> <td height="34" scope="col"><b>DAY/TIME</b></td> <td scope="col"><b>TITLE</b></td> <td scope="col"></td> <td scope="col"><b>PRESENTER</b></td> </tr> <?php do { ?> <tr> <td colspan="4"> <?php echo $row_master1Agenda['Date']; // print date </td> </tr> <?php if ($totalRows_master1Agenda>0) { $nested_query_detail2Agenda = str_replace("123456789", $row_master1Agenda['Talk_ID'], $query_detail2Agenda); mysql_select_db($database_AGCI); $detail2Agenda = mysql_query($nested_query_detail2Agenda, $AGCI) or die(mysql_error()); $row_detail2Agenda = mysql_fetch_assoc($detail2Agenda); $totalRows_detail2Agenda = mysql_num_rows($detail2Agenda); $nested_sw = false; if (isset($row_detail2Agenda) && is_array($row_detail2Agenda)) { do { //Nested repeat ?> <tr> <td width="75" valign="top"> <?php echo $row_detail2Agenda['Time']); // print time ?> </td> <td width="350" valign="top"> <?php echo $row_detail2Agenda['TalkTitle']; // print talk title ?> </td> <td width="20" valign="top"></td> <td valign="top"> <?php echo $row_detail2Agenda['PresenterNameFirst']; ?> <?php echo $row_detail2Agenda['PresenterNameLast']; // print presenter name?> </td> </tr> <?php } while ($row_detail2Agenda = mysql_fetch_assoc($detail2Agenda)); //Nested move next } } ?> <?php } while ($row_master1Agenda = mysql_fetch_assoc($master1Agenda)); ?> </table> </div> <?php mysql_free_result($master1Agenda); mysql_free_result($detail2Agenda); ?> Quote Link to comment https://forums.phpfreaks.com/topic/135712-nested-loop-for-displaying-agendacalendar-info/#findComment-707118 Share on other sites More sharing options...
mishasoni Posted December 9, 2008 Author Share Posted December 9, 2008 Anyone?????? Quote Link to comment https://forums.phpfreaks.com/topic/135712-nested-loop-for-displaying-agendacalendar-info/#findComment-710837 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.