Still have date display issues...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
influenceuk
Forum Commoner
Posts: 42
Joined: Tue May 08, 2007 7:48 am
Location: London, UK

Still have date display issues...

Post by influenceuk »

Hi, i am still having issues with displaying the date correctly, can someone check out my code and advise where i am going wrong please?

Basically the script works fine and will display the following...

Title Studio Release
A Item A Studio 2007-06-12

I am after getting the date to format like this - 12 June 2007.

I have tried putting in the Date Format bit but it wont work or i get errors :( Please help :?:

Code: Select all

<?php

include 'connect.php';

if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

$max_results = 15;

$from = (($page * $max_results) - $max_results); 

$sql = mysql_query("SELECT * FROM table2 WHERE `release` > CURRENT_DATE ORDER BY 'release' LIMIT $from, $max_results");
$bgcolor = "#E0E0E0";
    echo("<table>");
    echo"<tr class=titlebg><td><b>Title</b><td><b>Studio</b><td><b>Release Date</b></tr>";
    while($row = mysql_fetch_array($sql)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor."><td width=350 nowrap>");
    echo($row["title"]);
    echo("</td><td width=175 nowrap>");
    echo($row["studio"]);
    echo("</td><td align=\"center\">");
    echo($row["release"]);
    echo("</td></tr>");
    }

    echo("</table>");


$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM table2 WHERE `release` > CURRENT_DATE ORDER BY 'release'"),0);

$total_pages = ceil($total_results / $max_results);

echo "<center>Select a Page<br />";

if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Prev</a> -";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

if($page < $total_pages){
    $next = ($page + 1);
    echo "- <a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next</a>";
}
echo "</center>";
?>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You format the date using the date() function.
influenceuk
Forum Commoner
Posts: 42
Joined: Tue May 08, 2007 7:48 am
Location: London, UK

Post by influenceuk »

yeah i have tried these but it don't work or i get errors, are you or anyone able to provide examples or how i should code this please?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Code: Select all

echo date('n/j/Y', strtotime($fetchedObject->date));
influenceuk
Forum Commoner
Posts: 42
Joined: Tue May 08, 2007 7:48 am
Location: London, UK

Post by influenceuk »

cool but where would i put this in my code?
Post Reply