|
-
Jul 5th, 2002, 11:06 AM
#1
Thread Starter
Fanatic Member
reversing row order
hey
PHP Code:
$sql = "SELECT * FROM announcement ORDER BY announcementid DESC LIMIT $num, 5";
$result = mysql_query($sql);
$sql = "SELECT * FROM " . $result . " ORDER BY announcementid ORDER BY ASC)";
that doesnt work, i want to pick out the last 5 rows, and instead of them showing as 15-16-17-18-19-20, i want it go in reverse order, from 20 to 15.
if i do "ASC" instead of desc in the first sql statement, it picks 1->5 instead, i tried nested statements too, didnt work. ideas?
PHP Code:
$sql="SELECT * FROM (SELECT * FROM announcement LIMIT $num, 5) ORDER BY announcementid ORDER BY ASC"
$num = number of rows - 5
thanks
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jul 5th, 2002, 11:36 AM
#2
Hyperactive Member
if you want it to display tyem you coudl try putting htem into an array backwards, then itll print them forwards
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jul 5th, 2002, 11:39 AM
#3
New Member
PHP Code:
$sql = "SELECT * FROM `announcements` ORDER BY `id` DESC LIMIT $num, 5";
-
Jul 5th, 2002, 11:45 AM
#4
New Member
how about making a virtual table with the ones selected...
http://prog.proboards4.com/
-
Jul 5th, 2002, 12:50 PM
#5
Stuck in the 80s
Re: reversing row order
Originally posted by nabeels786
PHP Code:
$sql = "SELECT * FROM " . $result . " ORDER BY announcementid ORDER BY ASC)";
You don't need that second ORDER BY:
PHP Code:
$sql = "SELECT * FROM " . $result . " ORDER BY announcementid ASC)";
-
Jul 5th, 2002, 07:41 PM
#6
ASC doesn't have any impact on what rows you get. it just puts them in the order.
-
Jul 5th, 2002, 10:38 PM
#7
Stuck in the 80s
Well you can do the array thing that was suggested, or you can just get the number of records and subtract that by 5 to get your starting point.
-
Jul 5th, 2002, 11:09 PM
#8
Thread Starter
Fanatic Member
i tried everything suggested, nothing worked.
hobo, thats what ive done, subtracted by 5, and use the limit to get the last 5, i want to reverse the last 5 it gives me
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jul 6th, 2002, 12:04 AM
#9
Stuck in the 80s
This works fine for me:
PHP Code:
$sql = "SELECT * FROM table ORDER BY id DESC LIMIT 5";
-
Jul 6th, 2002, 10:12 AM
#10
why are you quering it twice? wouldn't this just work by itself
PHP Code:
$sql = "SELECT * FROM announcement ORDER BY announcementid asc LIMIT $num, 5";
$result = mysql_query($sql);
-
Jul 6th, 2002, 12:45 PM
#11
Thread Starter
Fanatic Member
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jul 6th, 2002, 01:42 PM
#12
Thread Starter
Fanatic Member
i dont know if it was the best way, but i stuck it into a for loop
PHP Code:
$num = mysql_num_rows(mysql_query("SELECT * FROM announcement"));
for($i=1;$i<=5;$i++){
$nnum=$num-$i;
$sql = "SELECT * FROM announcement LIMIT $nnum, 1";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
//its in order, output it how i want
}
}
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jul 6th, 2002, 03:41 PM
#13
Originally posted by nabeels786
it gives me 5->1
what id you echo $result?
if you use mysql_fetch_array() then it will do what you want.
-
Jul 6th, 2002, 05:22 PM
#14
Thread Starter
Fanatic Member
yeah i always do mysql_fetch_array()
the loop worked, i dunno why the other ones didnt
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jul 6th, 2002, 06:09 PM
#15
Originally posted by nabeels786
it gives me 5->1
so are you saying that when you echo the row out the id is 5 and goes down to 1? isn't that what you want.
-
Jul 6th, 2002, 06:31 PM
#16
Stuck in the 80s
my last post still works for me...
-
Jul 6th, 2002, 06:42 PM
#17
I know that is the way I do it also. just can't see what he is doing that is doesn't work.
-
Jul 6th, 2002, 06:47 PM
#18
Stuck in the 80s
Originally posted by scoutt
Iknow tha tis the way I do it also. just can't see what he is doing that is doesn't work.
drinking again?
-
Jul 9th, 2002, 04:06 PM
#19
Thread Starter
Fanatic Member
tried that, it gives me 15->20
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jul 9th, 2002, 04:08 PM
#20
Stuck in the 80s
Originally posted by nabeels786
tried that, it gives me 15->20
dude, I'm sorry, but you must be doing something retarded, because my solution works when I try it, and I'm pretty sure what scoutt is trying works for him. Why don't you post all of your code, plus a save of your database, so we can make it work for you?
-
Jul 9th, 2002, 07:08 PM
#21
does it literrally print that out?
so on the screen you see 15->20 or does it print
ID
---
15....
16...
17.....
18.....
19.....
20.....
isn't that what you want? if not just use DESC instead of ASC.
Micheal you are confusing the bejesus out of me
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|