Jump to content

Simple help from the pros please!


JSGTPD

Recommended Posts

Hey all

I have a webpage that is formatted to query my database and list the results like this

Date
DVD Move Release
DVD Move Release
DVD Move Release
DVD Move Release

Date
DVD Move Release
DVD Move Release
DVD Move Release
DVD Move Release

etc

Problem is it only list what is coming out for the current month. I want it to list the next 4 weeks worth of titiles, and then every monday get rid of the current week (which whould be the first one listed and do the NEXT 4 weeks worth of releases.

Here is my current PHP file. Any help would be great.

THANKS!

[code]<?
include("admin/config.php");

if(isset($_REQUEST['month']) && $_REQUEST['month']!='' && isset($_REQUEST['cat']) && $_REQUEST['cat']!='')
{

$month=$_REQUEST['month'];
$cat=$_REQUEST['cat'];
$current = date("Y-m-d", mktime(0, 0, 0, date("m")  , date("d")+7, date("Y")));
$thisweek1 = date("Y-m-d",mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")));
$current_org=date("Y-m-d", mktime(0, 0, 0, date("m")  , date("d"), date("Y")));
$thissql="SELECT * FROM dvd WHERE MONTH(rel_date) = '$month' AND status='DVD' AND rel_date > '$current_org' GROUP BY rel_date";

}
else
{
    $current = date("Y-m-d", mktime(0, 0, 0, date("m")  , date("d"), date("Y")));
    list($year, $month, $day) = split('[/.-]', $current);
    $thissql="SELECT * FROM dvd WHERE MONTH(rel_date) = '$month' AND status='DVD' AND rel_date > '$current' GROUP BY rel_date";
    //echo $thissql;
}
$thisresult=mysql_query($thissql) or die(mysql_error());

                                                                               
?>
<STYLE type=text/css>
A:link {COLOR: #0000FF; font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none}
A:visited {COLOR: #000000; font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none}
A:hover {COLOR: #FF0000; font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none}
A:active {COLOR: #FF0000; font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif; TEXT-DECORATION: none}
</STYLE>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<?
$thissql1="SELECT * FROM dvd WHERE MONTH(rel_date) = '$month' AND status='DVD' AND rel_date > '$current_org' GROUP BY rel_date";
//echo $thissql1;
//die();

$thisresult1=mysql_query($thissql) or die(mysql_error());
if(mysql_num_rows($thisresult1)!=0)
{
    while($nrowdvd=mysql_fetch_array($thisresult1))
    {

?>
  <tr>
    <td width="100%" valign="top">
      <table border="0" cellpadding="0" cellspacing="0" width="100%" style="margin-top: 1; margin-bottom: 1">
        <tr>
          <td width="100%" valign="top">
            <p style="margin-left: 10; margin-right: 10; margin-top: 5; margin-bottom: 5"><font face="Verdana" size="2">
            <b>
            <?
            $rel_date=$nrowdvd['rel_date'];               
            list($year,$month,$date)=explode("-",$rel_date);
            echo date("F j, Y", mktime(0, 0, 0, $month, $date, $year));
            ?>
            </b></font></td>
        </tr>
        <?
            $sql="SELECT * FROM dvd WHERE status='DVD' AND rel_date='$rel_date'";
            $result=mysql_query($sql) or die(mysql_error());
            while($newrowdvd=mysql_fetch_array($result))
            {
        ?>

        <tr>
          <td width="100%" valign="top">
            <p style="margin-left: 10; margin-right: 10; margin-top: 5; margin-bottom: 5"><font face="Verdana" size="2">
           
            <a target="_parent" href="index.php?action=listdvd&cat=dvd&dvd_id=<?=$newrowdvd['dvd_id']?>"><?=$newrowdvd['title']?></a></font></td>
        </tr>
        <?
        }
        ?>
       
      </table>
    </td>
  </tr>
  <?
  }
  }
  ?>
</table>[/code]
Link to comment
Share on other sites

I'd do something like this (haven't set up the db table, so untested)
[code]
<?php
function weekCommenceDate ($dt) {
    $dow = date('w', strtotime($dt));
    return strtotime ("$dt -$dow days");  //Sunday date
}

$thisMonday = date('Y-m-d', strtotime('this monday'));
$friday4 = date('Y-m-d', strtotime("$thisMonday +32 days"));

$sql = "SELECT title, rel_date
        FROM dvd
        WHERE rel_date BETWEEN '$thisMonday' AND '$friday4'
            AND status='DVD'
        ORDER BY rel_date";

$res = mysql_query($sql) or die(mysql_error());   

/**
* Store titles in array by week commence date
*/

while (list($title, $dt) = mysql_fetch_row($res))  {
    $releases[weekCommenceDate($dt)][] = $title;
}

/**
* output the array
*/

foreach ($releases as $wc => $titles) {
    echo "<br>Week commencing " . date('jS M', $wc) . "<br>\n";
    foreach ($titles as $movie) {
        echo "$movie<br>\n";
    }
}
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.