Page 1 of 1

Displaying Dates by Month

Posted: Tue Jan 13, 2009 12:55 pm
by amcgibbon
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I have currently set up a page to display a list of upcoming performance dates. This can be viewed here:

http://www.kidsnightonbroadway.com/kids ... _month.php

Here is what the code currently looks like:

The query:

Code: Select all

<?php require_once('Connections/KidsNightOnBroadway.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<!-- Broadway show query -->
<?php
mysql_select_db($database_KidsNightOnBroadway, $KidsNightOnBroadway);
$query_Broadway_Shows = "SELECT shows.showName, shows.sortName, shows.broadwayOffbroadway, events.eventDate, MONTHNAME(events.eventDate) AS myMonth, YEAR(events.eventDate) AS myYear FROM shows, events WHERE shows.show='1' AND shows.broadwayOffbroadway='Broadway' AND shows.showCode = events.showcode AND events.eventDate >= curdate() ORDER BY events.eventDate, shows.sortName";
$Broadway_Shows = mysql_query($query_Broadway_Shows, $KidsNightOnBroadway) or die(mysql_error());
$row_Broadway_Shows = mysql_fetch_assoc($Broadway_Shows);
$totalRows_Broadway_Shows = mysql_num_rows($Broadway_Shows);
?>
<!-- Off Broadway show query -->
<?php
mysql_select_db($database_KidsNightOnBroadway, $KidsNightOnBroadway);
$query_OffBroadway_Shows = "SELECT shows.showName, shows.sortName, shows.broadwayOffbroadway, events.eventDate, MONTHNAME(events.eventDate) AS myMonth, YEAR(events.eventDate) AS myYear FROM shows, events WHERE shows.show='1' AND shows.broadwayOffbroadway='Off Broadway' AND shows.showCode = events.showCode and events.eventDate >= curdate() ORDER BY events.eventDate, shows.sortName";
$OffBroadway_Shows = mysql_query($query_OffBroadway_Shows, $KidsNightOnBroadway) or die(mysql_error());
$row_OffBroadway_Shows = mysql_fetch_assoc($OffBroadway_Shows);
$totalRows_OffBroadway_Shows = mysql_num_rows($OffBroadway_Shows);
?>
 
<?
$sortName=$_GET['sortName']
 
?>
 
<?php
mysql_select_db($database_KidsNightOnBroadway, $KidsNightOnBroadway);
$query_getShow = "SELECT * FROM shows WHERE shows.sortName='$sortName'";
$getShow = mysql_query($query_getShow, $KidsNightOnBroadway) or die(mysql_error()); 
$row_getShow = mysql_fetch_assoc($getShow); $totalRows_getShow = mysql_num_rows($getShow); 
?>
Here is the php to display the list:

Code: Select all

     <table width="100%" border="0" cellspacing="0" cellpadding="10">
        <tr>
          <td width="33%"><strong>Show Date</strong></td>
          <td width="67%"><strong>Show Name</strong></td>
        </tr>
        <?php do { ?> <tr>
         
            <td><?php echo $row_Broadway_Shows['eventDate'] ?></td>
            <td><em><a href="kids_display_show.php?sortName=<?php echo $row_Broadway_Shows['sortName']?>"><?php echo $row_Broadway_Shows['showName'] ?></a></em></td>
            
</tr><?php } while ($row_Broadway_Shows = mysql_fetch_assoc($Broadway_Shows)); ?>
 
      </table>
      <p><strong>Off-Broadway Shows</strong></p>
      <table width="100%" border="0" cellspacing="0" cellpadding="10">
        <tr>
          <td width="33%"><strong>Show Date</strong></td>
          <td width="67%"><strong>Show Name</strong></td>
        </tr>
        <?php do { ?>
          <tr>
            <td><?php echo $row_OffBroadway_Shows['eventDate'] ?></td>
            <td><em><a href="kids_display_show.php?sortName=<?php echo $row_OffBroadway_Shows['sortName']?>"><?php echo $row_OffBroadway_Shows['showName'] ?></a></em></td>
          </tr>
          <?php } while ($row_OffBroadway_Shows = mysql_fetch_assoc($OffBroadway_Shows)); ?>
      </table>
I need to display any dates moving forward broken down by broadway then off-broadway and then by by month within the two. If anyone has any suggestions I would greatly appreciate some help on this.

Thanks in advance,
Andy


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Displaying Dates by Month

Posted: Tue Jan 13, 2009 6:12 pm
by it2051229
i can't imagine what you want...... what?

Re: Displaying Dates by Month

Posted: Tue Jan 13, 2009 6:47 pm
by amcgibbon
Sorry for the confusion. I currently have the above code set up to sort available shows by Broadway and Off-Broadway. I also want to break out each month under each of those headings. Example:

BROADWAY

February

Show Date Show Title
Show Date Show Title

March

Show Date Show Title
Show Date Show Title

OFF-BROADWAY

February

Show Date Show Title
Show Date Show Title

March

Show Date Show Title
Show Date Show Title




I hope this helps to clarify this.

Thanks,
Andy

Re: Displaying Dates by Month

Posted: Tue Jan 13, 2009 11:36 pm
by it2051229
ok i do this the hard way

Code: Select all

 
    $monthQuery = mysql_query("blah blah blah");
    
    for($i = 0; $i < mysql_num_rows($monthQuery); $i++)
    {
        $month = mysql_result($monthQuery, $i, "the month field or date field");
        
        $showQuery = mysql_query("query all shows and there date and titl WHERE THERE MONTH IS $month") or die(mysql_error());
        
        for($j = 0; $j < mysql_num_rows($showQuery); $j++)
        {
            $showTitle = mysql_result($showQuery, $j, "the title field");
            $showDate = mysql_result($showQuery, $j, "the date field");
            
            // then we display
        }
    }