Jump to content

**SOLVED** "Order BY" problem


crag

Recommended Posts

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

[code]
<?php
                
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 />';
    }                    
?>
[/code]
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:
[code]
<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>
</form>
[/code]

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?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/6878-solved-order-by-problem/
Share on other sites

Archived

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

×
×
  • 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.