Displaying certain results at the top....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Displaying certain results at the top....

Post by Mr. Tech »

I have an article script. What I am wanting to do is to display from a mysql database the "Featured articles" before the normal articles which I will order by the time they where added.

How can I do this without having to use two mysql querys? The results are also in pages.

I tried something like this:

mysql_query("select * from ".$tbl_name."_articles order by featured,uptime desc limit $vstart,$Spagecut");

Didn't work...
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

How is the articles table set up?
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

What do you mean axactly?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

In other words, what fields does it have, can you give an example row?

Ex:

Code: Select all

+-----+----------+---------+
| ID  | Article  |  Text   |
+-----+----------+---------+
|  1  | PHP Tips | blah... |
+-----+----------+---------+
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Code: Select all

id     |     title     |     cat     |     description     |     author     |     type     |     featured     |     article     |     uptime


1     |    PHP Tips      |    1     |    description here     |    My Name      |    1     |    1     |    Article text blah blah     |    1046405638
In featured, 1 means it is featured 0 or left blank means its not featured
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Is what I want possible?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

I don't see why "order by featured,uptime" doesn't work. What happens when you do it this way?
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

It puts the one that is featured down the bottom on desc and asc... is there a number i need to put in featured to make it go up the top?
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Post by Mr. Tech »

Would this work:

If it is featured, -1
If it isnt featured, 0

And then put featured,uptime desc in the quey.

It seemed to work I just want to make sure ;)
Post Reply