Jump to content


**SOLVED** "Order BY" problem

  • Please log in to reply
1 reply to this topic

#1 crag

  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 08 April 2006 - 02:53 PM

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?


#2 crag

  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 08 April 2006 - 05:06 PM

I managed to work it out for myself - maybe I should have tried harder in the first place before posting here.

A lesson learnt

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users