SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot bopjo1's Avatar
    Join Date
    Jun 2007
    Location
    Tampa, FL
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help displaying data

    Hi folks,

    I have a list of gigs for a band that I want to display. The gig data will consist of the name of the gig, address, etc.

    I know how to store that in the database and select it, but I want to display each gig as a list item under a heading of the MONTH that the gig is in. Like this:

    December

    • Gig 1
    • Gig 2
    • Gig 3


    In the database I have a table named "gigs" that contains all the data, including a field for the month. I also have another table named "months" that contains all 12 months. So in my query I write "select all the data from both tables where gigs.month = months.month". This links each gig with it's proper month and only retrieves months that have gigs in them. But after that, I'm hitting a road block on how to display each gig under each month, and not show any months where there aren't any gigs. I have a while loop:

    Code:
    while ($row = mysql_fetch_array($result)) {
    	echo '<h4>' . $row['month'] . '</h4>';	
    	echo '<p>' . $row['day'] . ', ' . $row['month'] . ' ' . $row['gig_date'] . ' - ' . $row['gig_name'] . ' - ' . $row['gig_time'] . '<br/>';
    	  echo $row['address'] . '<br/>';
    	  echo $row['phone'];
    	
    }
    Unfortunately this gives me:

    December
    • Gig 1


    December
    • Gig 2


    January
    • Gig 3


    January
    • Gig 4


    etc., and I want all gigs per month to under that month's header.

    Any ideas on how to do this?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Keep track of the current month being displayed and show the month header only when the month changes.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •