473,396 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

MySQL sort by date

I have a datebase of events. I have a form that adds to it, and I have a
form that removes from it (with checkboxes). And I have a php file that
will view all the events, either all of them or just the events happening
after "today." These events are added randomly, and I want my php file that
views the events to display the results in order of when they are happening.
Any suggestions? I have seen a CREATE VIEW query that looks promising. Is
that a good way to do it, just to create an on-the-fly table that is sorted
and display the reults from that one?

Thanks,

Paul
Jul 17 '05 #1
3 18576
"SELECT * FROM table_name ORDER BY time_field;"

of course this supposes that your "time_field" is in the form of a
mysql-readable time format. if it isnt, you may have to convert it with
mysql/php's time/date functions.

- JP

"Paul Brown" <gt*****@mail.gatech.edu> wrote in message
news:c6**********@news-int.gatech.edu...
I have a datebase of events. I have a form that adds to it, and I have a
form that removes from it (with checkboxes). And I have a php file that
will view all the events, either all of them or just the events happening
after "today." These events are added randomly, and I want my php file that views the events to display the results in order of when they are happening. Any suggestions? I have seen a CREATE VIEW query that looks promising. Is that a good way to do it, just to create an on-the-fly table that is sorted and display the reults from that one?

Thanks,

Paul

Jul 17 '05 #2
I noticed that Message-ID: <6Xahc.24291$hw5.38560@attbi_s53> from
kingofkolt contained the following:
"SELECT * FROM table_name ORDER BY time_field;"

of course this supposes that your "time_field" is in the form of a
mysql-readable time format. if it isnt, you may have to convert it with
mysql/php's time/date functions.


Indeed.

I have a database where dates are stored in MySql date format. To get
the next event I do

$result = mysql_query("SELECT UNIX_TIMESTAMP(date) AS unixdate FROM
tblDates WHERE date > now() ORDER BY 'unixdate'" ,$db);
$myrow = mysql_fetch_array($result);
$num_rows = mysql_num_rows($result);
$RealDate = date("F jS, Y", $myrow["unixdate"]);

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
In message <c6**********@news-int.gatech.edu>, Paul Brown
<gt*****@mail.gatech.edu> writes
I have a datebase of events. I have a form that adds to it, and I have a
form that removes from it (with checkboxes). And I have a php file that
will view all the events, either all of them or just the events happening
after "today." These events are added randomly, and I want my php file that
views the events to display the results in order of when they are happening.
Any suggestions? I have seen a CREATE VIEW query that looks promising. Is
that a good way to do it, just to create an on-the-fly table that is sorted
and display the reults from that one?
If you just have a DATE in each row, an AUTOINCREMENT column would give
you a way of being quite sure which order they were added in.

You are getting a random result I believe as when a row is deleted from
a table, the space is not 'close up' but simply marked for re-use and if
there is no ORDER BY on the select clause it is presumably scanning the
table and presenting the results in the order it gets them in. At least
this happens with Informix. ;-)
Thanks,

Paul


--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Yulia Yegenov | last post by:
I have a query that looks like this: (I insert the date created with the php date function) $status = "Active"; //(I cannot use the mysql timestamp function for other reason). $curdate =...
0
by: Philip Stoev | last post by:
Hi all, Please tell me if any of this makes sense. Any pointers to relevant projects/articles will be much appreciated. Philip Stoev http://www.stoev.org/pivot/manifest.htm ...
2
by: Arc | last post by:
Sorry if this has been gone over before, but I checked google groups and I couldn't find anything. Does anyone here have any idea when 4.1.x will be released into production (i.e. come out of...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
0
by: Bucker | last post by:
Could someone view the following that I copied from phpMyAdmin and tell me from the statistics if are server is running OK? Does it look like we will have problems as more people hit our server?...
1
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname,...
6
by: Brandon | last post by:
I'm using PHP with MySQL 4.x and was having trouble converting a datetime from MySQL into a formatted string until I ran across this solution that converts a YYYY-MM-DD HH:MM:SS string into a...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
30
by: Einstein30000 | last post by:
Hi, in one of my php-scripts is the following query (with an already open db-connection): $q = "INSERT INTO main (name, img, descr, from, size, format, cat, host, link, date) VALUES ('$name',...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.