Forum Moderators: coopster

Message Too Old, No Replies

problems with order by date desc

Can't show what I want in reverse order

         

brokenbricks

4:52 pm on Sep 13, 2005 (gmt 0)

10+ Year Member



I am very new at php/mysql

I have a script that scrolls through a number of widgets one by one in order from first to last...

I would like to add the option to scroll through only the 'newest widgets' , so I'd accomplish that by showing them in reverse order

my code for viewing in sequence is this:

$sql="select max(id) as maxid from user ";
$rez=mysql_query($sql,$dblnk);
$row=mysql_fetch_array($rez);
$maxid=$row['maxid'];
$sql="select min(id) as minid from user ";
$rez=mysql_query($sql,$dblnk);
$row=mysql_fetch_array($rez);
$minid=$row['minid'];
//echo $maxid;
if((!isset($widget_id)) or ($widget_id==$maxid))
$sql="select * from user order by id asc limit 0,1";
else $sql="select * from user where id >$widget_id order by id asc limit 0,1";
$rez=mysql_query($sql,$dblnk);
$row=mysql_fetch_array($rez);
if(!isset($id))
$id=$row['id'];

and a link on the page
<a href="view.php?widget_id=<? echo $id;?>">

will show the next widget

I have tried many variations using:

$sql="select * from user ORDER BY date_added DESC";

I am able to display the newest widget but cannot scroll back through them in descending order

What simple code change can I make to do that?

Thanks Very Much

brokenbricks

7:49 pm on Sep 13, 2005 (gmt 0)

10+ Year Member



anyone?

jd01

8:12 pm on Sep 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like you will need to use a variable limit:

limit 0,1 will give you the first result, to get the second you would need 1,1 and the third 2,1 and so on... Then you should be able to get the correct result from either order (ASC or DESC) statement.

I would use the page num EG $start=$page-1; should get you the right answer to start.

Justin

brokenbricks

8:24 pm on Sep 13, 2005 (gmt 0)

10+ Year Member



hmm
thanks

but I am just further confused

I hired a programmer and he left me with this garbage pile of code