473,473 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

order by tables question

I just made a table sortable by column headers by reading a thread
posted here a while ago. Here is the code simplified:

$sort_order = 'id';
if($order == 'jobtitle'){
$sort_order = 'jobtitle';
}else if($order == 'district'){
$sort_order = 'district';
}
else if($order == 'date'){
$sort_order = 'date';
}

"SELECT * FROM table ORDER BY $sort_order ASC";

It works just as I thought it would. But, my question is how do I make
it so 'id' (set to auto increment) or 'date' defaults to DESC (so the
most recent post is always on top), while at the same time the links on
the column headers sorts by ASC (like it currently does).
Thanks.
Jul 17 '05 #1
2 1466
Neal (pi****@comcast.net) wrote:
: I just made a table sortable by column headers by reading a thread
: posted here a while ago. Here is the code simplified:

: $sort_order = 'id';
: if($order == 'jobtitle'){
: $sort_order = 'jobtitle';
: }else if($order == 'district'){
: $sort_order = 'district';
: }
: else if($order == 'date'){
: $sort_order = 'date';
: }

: "SELECT * FROM table ORDER BY $sort_order ASC";

: It works just as I thought it would. But, my question is how do I make
: it so 'id' (set to auto increment) or 'date' defaults to DESC (so the
: most recent post is always on top), while at the same time the links on
: the column headers sorts by ASC (like it currently does).
: Thanks.

I'm not 100% clear on what you mean, but perhaps something like the
following minor variation would work better for you

$sort_order = 'id DESC';
if($order == 'jobtitle'){
$sort_order = 'jobtitle ASC';
}else if($order == 'district'){
$sort_order = 'district ASC';
}
else if($order == 'date'){
$sort_order = 'date DESC';
}

"SELECT * FROM table ORDER BY $sort_order";
--

This space not for rent.
Jul 17 '05 #2
Malcolm Dew-Jones wrote:
I'm not 100% clear on what you mean, but perhaps something like the
following minor variation would work better for you

$sort_order = 'id DESC';
if($order == 'jobtitle'){
$sort_order = 'jobtitle ASC';
}else if($order == 'district'){
$sort_order = 'district ASC';
}
else if($order == 'date'){
$sort_order = 'date DESC';
}

"SELECT * FROM table ORDER BY $sort_order";
--


Exactly what I was looking for (I should've known).
Thanks.
Jul 17 '05 #3

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

Similar topics

1
by: Doug | last post by:
I have a pretty long query that ends with ORDER BY R.r_recent_hits DESC LIMIT 0, 1 I also have an index on R.r_recent_hits. I did an explain select and got this: ALL - which means (from...
2
by: One's Too Many | last post by:
Ran into a strange problem today: 8.1.7 on AIX 4.3.3 Database and applications had been working fine for two years and all of a sudden a couple of regularly-run queries are now no longer...
0
by: | last post by:
As we're on this topic in another thread right now: Say I have a SELECT query from more than one table and with some = conditions, does it matter in what order I enter the tables in the FROM =...
4
by: Sri | last post by:
I am writing a download process in which i have a condition where i need to join four tables. Each table have lot of data say around 300000 recs. my question is when i am doing the joins on...
5
by: tilak.negi | last post by:
We have one single hash (#) table, in which we insert data processing priority wise (after calculating priority). for. e.g. Company Product Priority Prod. Qty Prod_Plan_Date C1...
6
by: Együd Csaba | last post by:
Hi All, I'd like to dump out my database using plain text format. Everything is ok, but the bytea filds. Restoring the dump file (using <<psql -f LO_TRY_INSERT_BYTEA.sql tmp7>>) it sends an...
2
by: Morten K. Poulsen | last post by:
(re-post) Dear list, Please let me know if this is not the list to ask this kind of question. I am trying to optimize a query that joins two relatively large (750000 rows in each) tables....
0
by: Kaur | last post by:
Hi, I have created a report based on a cross tab query and would like to Sort the column heading of the report based on the sort order of another field. I have three tables called survey...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.