views:

190

answers:

2

I have an events calendar written in PHP, with the following pagination script that I obtained from a free PHP site. This is the basic script (entitled PmcPagination.php):

http://pastebin.com/f7c5a4a90 (linked here for convenience, too lengthy to post in full!)

It works to the extent that it shows all events - but the dates do not tally with the database, and as such are all listed as the following: Event 1 on January 1st, 1970 - 1:00am "Family Event" Set Reminder Event 2 on January 1st, 1970 - 1:00am "Historical Event" Set Reminder ... and so on, for the next 20, 30, 40 records.

What should I do to fix this date/time error in the code? It's rendering OK ... for now but the date/time thing is proving tricky to fix.

Research on Google and various PHP sites did not help, so where has this gone wrong? (The code isn't my own, but an adapted version of someone else's!)

+1  A: 

Anything on a date of January 1st, 1970 is probably a date of 0. Check to make sure that the value is not 0 and is a valid integer.

Ignacio Vazquez-Abrams
See below for full reply...
John Smith
A: 

The date worked in a different version of the script - this is the original:

<?PHP
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","PASSWORD"); 

//select which database you want to edit
mysql_select_db("events"); 

// Select only results for today and future
$result = mysql_query("SELECT * FROM `eventup1` WHERE `expiration` >=NOW() ORDER BY `airdate` ASC LIMIT 20 OFFSET 10");

while($r = mysql_fetch_array($result)) { 

    $event  = $r["event"];
    $venue     = $r["venue"];
    $eventdate     = strtotime($r['eventdate']);
    $expiration = strtotime($r['expiration']);
    $eventactive     = $r["eventactive"];
    $setreminder = $r["setreminder"];
    $now         = time();

    if(date('Y-m-d') == date('Y-m-d', $airdate)) {
        // Same date, show only time
        $dateFormat = 'g:ia';
    } elseif(date('Y') == date('Y', $airdate)) {
        // Same year, show date without year
        $dateFormat = 'F jS - g:ia';
    } else {
        // Other cases, show full date
        $dateFormat = 'F jS, Y - g:ia';
    }

    $eventdate = date($dateFormat, $airdate);
    echo "<tr><td><b>$event</b></td><td>showing on $venue</td>";
    echo "<td>$eventdate</td><td>$eventactive</td><td>$setreminder</td></tr>";
}
?>

Don't know why I get the error in the PmcPagination script but not this one... anyone know why?

How could I get the above script to paginate, in the style of this URL: http://library.digiguide.com/lib/programmenextshowing/Police%2C+Camera%2C+Action!-12578 (notice how the pagination is below the footer).

This is my basic page coding:

<?php 

include("header.php"); include("eventschedule.php"); include("event-footer1.php"); include("footer.php"); ?>

(eventschedule.php is the code submitted above. It works with records limited, but I can't paginate them properly!)

Thank you for your help above, if anyone knows how to fix this, I'll add reputation when I can!

John Smith