dmirsch Posted November 26, 2011 Share Posted November 26, 2011 I am trying to have an event with each performance listed for the event underneath. I have worked with the MySQL Forum and have gotten to the point where my coding for MySQL is complete, but it still will not work. I was told from the MySQL Forum group that I need to now post these in this forum... Here's how I tried the coding: <p class="categoryHeader">Theatre</p><?php $last_eventtitle = NULL; // remember the last EventTitle while ($Row = mysqli_fetch_assoc($TheatreResult)){ $eventtitle = $Row['EventTitle']; if($last_eventtitle != $eventtitle){ // a new or the first EventTitle was found echo '<p>'; if($Row['Ranking']<10){ echo '<img src="http://www.myalaskacenter.com/images/logos/acpa/weblogo-small_nowords.jpg" alt="Alaska Center for the Performing Arts" width="80" height="80" border="0" align="right">'; } if ($Row['FreeEvents']==TRUE){ echo '<img src="http://www.myalaskacenter.com/images/free.gif" alt="Free Event" width="67" height="64" align="right" border="0">'; } echo '<a href="' . $Row['ShoWareEventLink'] . '"><img src="https://alaskapac.centertix.net/UPLImage/' . $Row['thumb'] . '" alt="' . $Row['EventTitle'] . '" title="' . $Row['EventTitle'] . '" align="left" border="0" style="padding-right:5px"><span class="Heading3_blue"><br />' . $Row['EventTitle'] . '</span>'; echo '<br />Presented by <a href="' . $Row['website'] .'" target="_blank">' . $Row['Presenter'] . '</a><br />'; if($last_eventtitle != NULL){ // not the first EventTitle, close out the previous section echo '<br />'.date("l, F j, Y", strtotime($Row['startDateTime']). ' at ' . date("g:i a", strtotime($Row['startDateTime']))).' - <a href="'.$Row['VenueSite'].'" target="_blank">'.$Row['VenueName'].'</a>'; } $last_eventtitle = $eventtitle; // save the new EventTitle // output the heading/start a new section echo '<br />'.date("l, F j, Y", strtotime($Row['startDateTime']). ' at ' . date("g:i a", strtotime($Row['startDateTime']))).' - <a href="'.$Row['VenueSite'].'" target="_blank">'.$Row['VenueName'].'</a>'; echo '<br /><br /></p><hr>'; } } ?> Now it lists the first performances correctly; although it does NOT list the correct number of performances and the first performance is sometimes listed twice -- so almost there. See webpage http://www.myalaskacenter.com/centermail/_upcomingevents.php. For example, Anchorage Youth Symphony only has one performance, but it lists 2; while It's a Wonderful Life has 17 performances, but it lists only 2. What am I doing wrong still? Quote Link to comment https://forums.phpfreaks.com/topic/251862-sublisting-within-a-listing/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 27, 2011 Share Posted November 27, 2011 The following is the logic you are trying to use - <?php $last_eventtitle = NULL; // remember the last EventTitle while ($Row = mysqli_fetch_assoc($TheatreResult)){ $eventtitle = $Row['EventTitle']; if($last_eventtitle != $eventtitle){ // a new or the first EventTitle was found if($last_eventtitle != NULL){ // not the first EventTitle, close out the previous section // code to close out the previous section goes here... (if your layout needs to do this) } $last_eventtitle = $eventtitle; // save the new EventTitle // output the heading/start a new section // code to output the heading goes here... } // code to output each piece of data under the heading goes here... } // code to close out the last section goes here... (if your layout needs to do this) ?> The only places you should be echoing anything are where the comments in the above indicate. Quote Link to comment https://forums.phpfreaks.com/topic/251862-sublisting-within-a-listing/#findComment-1291565 Share on other sites More sharing options...
dmirsch Posted November 28, 2011 Author Share Posted November 28, 2011 OK, I need to show ALL performances for EACH EventTitle...so almost there. Here's the coding: <p class="Headline2_bts">Theatre</p><?php $last_eventtitle = NULL; // remember the last EventTitle while ($Row = mysqli_fetch_assoc($TheatreResult)){ $eventtitle = $Row['EventTitle']; if($last_eventtitle != $eventtitle){ // a new or the first EventTitle was found if($last_eventtitle != NULL){ // not the first EventTitle, close out the previous section // code to close out the previous section goes here... (if your layout needs to do this) echo '<br /><br /></p><hr>'; } $last_eventtitle = $eventtitle; // save the new EventTitle // output the heading/start a new section // code to output the heading goes here... echo '<p>'; if($Row['Ranking']<10){ echo '<img src="http://www.myalaskacenter.com/images/logos/acpa/weblogo-small_nowords.jpg" alt="Alaska Center for the Performing Arts" width="80" height="80" border="0" align="right">'; } if ($Row['FreeEvents']!=FALSE){ echo '<img src="http://www.myalaskacenter.com/images/free.gif" alt="Free Event" width="67" height="64" align="right" border="0">'; } echo '<a href="' . $Row['ShoWareEventLink'] . '"><img src="https://alaskapac.centertix.net/UPLImage/' . $Row['thumb'] . '" alt="' . $Row['EventTitle'] . '" title="' . $Row['EventTitle'] . '" align="left" border="0" style="padding-right:5px"><span class="Heading3_blue"><br />' . $Row['EventTitle'] . '</span>'; echo '<br />Presented by <a href="' . $Row['website'] .'" target="_blank">' . $Row['Presenter'] . '</a>'; //NEED A WHILE STATEMENT HERE TO SHOW EACH PERFORMANCE FOR THIS EventTitle echo '<br />'.$Row['startDate']. ' at ' . $Row['startTime'].' - <a href="'.$Row['VenueSite'].'" target="_blank">'.$Row['VenueName'].'</a>'; //NEED TO CLOSE THE WHILE STATEMENT HERE } } // code to close out the last section goes here... (if your layout needs to do this) ?> Everything else seems to work correctly, but only one performance is listed. Quote Link to comment https://forums.phpfreaks.com/topic/251862-sublisting-within-a-listing/#findComment-1291948 Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2011 Share Posted November 29, 2011 only one performance is listed. That's because you are NOT outputting the data for each performance where the logic requires you to do so. There was a comment at the correct place - // code to output each piece of data under the heading goes here... Quote Link to comment https://forums.phpfreaks.com/topic/251862-sublisting-within-a-listing/#findComment-1292093 Share on other sites More sharing options...
dmirsch Posted November 29, 2011 Author Share Posted November 29, 2011 THANK YOU PFMaBiSmAd! It's working now!!! Quote Link to comment https://forums.phpfreaks.com/topic/251862-sublisting-within-a-listing/#findComment-1292306 Share on other sites More sharing options...
dmirsch Posted December 2, 2011 Author Share Posted December 2, 2011 I am still attempting to use this code and now have found an issue on a different webpage. In the previous webpage, I hard coded the MainCategory. Now since there are more than just 4 MainCategories in the new webpage, I would like the coding to find them itself. In looking at the coding you supplied, I thought it would go under "output the heading/start a new section" but this does not allow it to show up. Here's the code: <?php //PROCEDURES $last_SUBcategory = NULL; // remember the last SUBcategory while ($Row = mysqli_fetch_assoc($Result)){ $SUBcategory = $Row['SUBcategory']; if($last_SUBcategory != $eventtitle){ // a new or the first SUBcategory was found if($last_SUBcategory != NULL){ // not the first SUBcategory, close out the previous section // code to close out the previous section goes here... (if your layout needs to do this) echo "</ul>"; echo '<hr /><hr />'; } $last_SUBcategory = $SUBcategory; // save the new EventTitle // output the heading/start a new section; code to output the heading goes here... echo '<h2>'.$Row['SUBcategory'].'</h2><ul>'; } //NEED A WHILE STATEMENT HERE TO SHOW EACH Item FOR THIS SUBcategory echo '<h3>'.$Row['Item'].'</h3>'; echo '<p>'; if ($Row['Attachment'] != NULL) { echo '<a href="/pdfs/coupons-promotions/"'. $Row['Attachment'] . ' target="_blank"><img src="http://www.myalaskacenter.com/images/logos/PDF.png" width="15px" height="15px" alt="Download PDF File" title="Download PDF File"> '.$Row['Attachment'].'</a>'; } if ($Row['Image'] != NULL) { echo ' <img src="/pdfs/coupons-promotions/'.$Row['Image'].'" width="40px" height="40px" alt="'. $Row['Item'] . '" title="'. $Row['Item'] . '"align="left">'; } echo $Row['Description']; //NEED TO CLOSE THE WHILE STATEMENT HERE TO SHOW EACH PERFORMANCE FOR THIS SUBcategory } // code to close out the last section goes here... (if your layout needs to do this) ?> In this case the MainCategory=SUBcategory, and they are not showing up -- see http://www.acpacenterstage.com/centertix-ticketsellers/knowledgebase-procedures.php for an example. PFMaBiSmAd, I am hoping you will help me out again since you were so instrumental in making this work last time! If someone else can give me the solution, I would be just as thankful, though Quote Link to comment https://forums.phpfreaks.com/topic/251862-sublisting-within-a-listing/#findComment-1293682 Share on other sites More sharing options...
dmirsch Posted December 5, 2011 Author Share Posted December 5, 2011 PFMaBiSmAd has helped me out with this and was very helpful. Now I need to step back one more time to the Marketing Category (i.e., Theatre vs Concert). So my listing would be: Marketing Category Event Title Performance Date & Venue Should I do the while code inside the while code? Quote Link to comment https://forums.phpfreaks.com/topic/251862-sublisting-within-a-listing/#findComment-1294734 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.