Jump to content


This topic is now archived and is closed to further replies.


**SOLVED** "Order BY" problem

Recommended Posts

I am using this code to output the formatted date to screen which produces the result:
"Saturday 1st April" for example.

include_once 'db.inc.php';
// Display all gig listings to page.
$result = @mysql_query('SELECT id, bandname, giginfo, gigtime,
DATE_FORMAT(gigdate, "%W %D %M") AS gigdate FROM giglist ORDER BY gigdate');
if(!$result) {
     exit ('<p>Error performing query ' . mysql_error() . '</p>');
while($row = mysql_fetch_array($result)) {
    $gigid = $row['id'];
    $bandname = htmlspecialchars($row['bandname']);
    $giginfo = htmlspecialchars($row['giginfo']);
    $gigtime = htmlspecialchars($row['gigtime']);
    $gigdate = $row['gigdate'];
    echo '<fieldset><p><b>' . $gigdate . '  |  ' .
        $bandname . '<br /></b>' . $giginfo . '<br /><b>' .
        $gigtime . '</b></p></fieldset><br />';
My problem is when using "ORDER BY gigdate" it orders by the day (Saturday) and not the actual full date itself so giving me the result where all mondays are grouped together then tuesdays and so on.

Also in my form:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <p><label>Enter date:</label><input name="gigdate" type="text" size="20" maxlength="20" /></p>
    <p><label>Enter band name:</label><input name="bandname" type="text" size="40" maxlength="40" />
    <p><label>Enter gig details:</label><textarea name="giginfo" cols="50" rows="10"></textarea></p>
    <p><label>Enter gig time:</label><input name="gigtime" type="text" size="20" maxlength="20" /></p>
    <p><input name="submit" type="submit" value="submit" class="submit" /></p>

I have to enter the date as YYYY/MM/DD where I would like the user to be able to enter the date as DD/MM/YYY.

Can anyone tell me how to achieve this?


Share this post

Link to post
Share on other sites
I managed to work it out for myself - maybe I should have tried harder in the first place before posting here.

A lesson learnt

Share this post

Link to post
Share on other sites


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.