Page 1 of 1

Ordering rows

Posted: Fri Jun 17, 2005 9:02 am
by webdivany
Hi, I'm having a problem ordering rows. The URL to the site is: http://www.glenridgeseniorcenter.com/main.php
On the side there's a box that says "Upcoming Events >"
It is pulling the table and displaying only the rows that have the month as the current month. However I want it to do that as well as ordering it, because right now the days are out of order.

The table name is:
event_2

The fields are:
month
day
event

This is the code I have right now:

Code: Select all

<?
$username="";
$password="";
$database="";

mysql_connect(localhost,$username,$password); 
@mysql_select_db($database) or die( "Unable to select database"); 
$result=mysql_query("select * from event_2 where month=".  

date("n")); 
for($i=1;$i<=mysql_num_rows($result);$i++){ 
                        $row=mysql_fetch_array($result); 
?> 
<b><? echo $row['month'] ?>/<? echo $row['day'] ?></b> - <? echo $row['event'] ?><br> 
     <? 
        } 
        ?>

I need help in ordering the rows using 'day'

I can't seem to get it. I tried ORDER by day
and still nothing, I get errors.

Posted: Fri Jun 17, 2005 10:33 am
by phpScott
what does your database table look like?

Posted: Fri Jun 17, 2005 1:16 pm
by webdivany
--
-- Table structure for table `event_2`
--

CREATE TABLE `event_2` (
`month` char(2) NOT NULL default '',
`day` char(2) NOT NULL default '',
`event` varchar(100) NOT NULL default ''
) TYPE=MyISAM;

Posted: Fri Jun 17, 2005 1:30 pm
by John Cartwright

Code: Select all

$result=mysql_query("SELECT * FROM `event_2` WHERE `month` = '".date("n")."' ORDER BY `day` DESC");

Posted: Sat Jun 18, 2005 10:23 am
by dreamline
I'd use something like:
order by day desc,'dd-mm-yyyy' (for sorting highest date first)
order by day asc,'dd-mm-yyyy' (for sorting lowest date first)

There are more swithes used for the date format but those are all in the php manual, don't know em all by heart.. lol

:)