corillo181 Posted June 14, 2007 Share Posted June 14, 2007 how would i put a desc and asc order so only the next 2 and the last 2 pictures are shown? <? $selectless=mysql_query("SELECT * FROM tra_gallery_photo WHERE album_id='$album' AND photo_id<'$photo_id' LIMIT 2 ")or die(mysql_error()); while($lessthumb=mysql_fetch_array($selectless)){?> <a href="displayimage.php?album=<?=$album?>&ptd=<?=$lessthumb['photo_id']?>"><img src="<?=$lessthumb['thumb_path']?>" alt="<?=$lessthumb['thumb_path']?>" /></a> <? }?><? $picture=mysql_query("SELECT thumb_path FROM tra_gallery_photo WHERE album_id='$album' AND photo_id='$photo_id'")or die(mysql_error()); $display=mysql_fetch_array($picture); ?> <img src="<?=$display['thumb_path']?>" alt="<?=$display['image_path']?>"/> <? $select=mysql_query("SELECT * FROM tra_gallery_photo WHERE album_id='$album' AND photo_id>'$photo_id' LIMIT 2")or die(mysql_error()); while($morethumb=mysql_fetch_array($select)){?> <a href="displayimage.php?album=<?=$album?>&ptd=<?=$morethumb['photo_id']?>"><img src="<?=$morethumb['thumb_path']?>" alt="<?=$morethumb['thumb_path']?>"/></a> <? }?> [code] [/code] Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/ Share on other sites More sharing options...
Full-Demon Posted June 14, 2007 Share Posted June 14, 2007 To use desc or asc you can use the ORDER command in your query, followed by the column you want to order, followed by DESC or ASC... Hope that helps. FD Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-274858 Share on other sites More sharing options...
corillo181 Posted June 14, 2007 Author Share Posted June 14, 2007 i try using a desc and if the current image is 22 it display the fallow wing | 22 | 21 | 23 | 24 | 25 | if i use asc it goes back tot he first image and displays | 1 | 2 | 23 | 24 | 25 | notice that i only apply to the first 2 images before the current image. Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-274865 Share on other sites More sharing options...
corillo181 Posted June 15, 2007 Author Share Posted June 15, 2007 no answer? Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275102 Share on other sites More sharing options...
1bradillac Posted June 15, 2007 Share Posted June 15, 2007 Say you have 50 rows in a table. To show 1 | 2 | 22 | 49 | 50 "SELECT * FROM table ORDER BY id ASC LIMIT 2" and "SELECT * FROM table ORDER BY id DESC LIMIT 2" To show 20 | 21 | 22 | 23 | 24 $currentimage = 22; $currentimage = $currentimage - 2; $blah = mysql_query("SELECT * FROM table WHERE id = $currentimage ORDER BY id ASC" LIMIT 5); while ($row = mysql_fetch_array($blah)){ echo $row["id"]; } Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275104 Share on other sites More sharing options...
corillo181 Posted June 15, 2007 Author Share Posted June 15, 2007 that method does not work if i remove a record.. because is going to search for the number -2 so if the number are not in order it wont work. Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275124 Share on other sites More sharing options...
corillo181 Posted June 15, 2007 Author Share Posted June 15, 2007 no pros here to answer that question? Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275370 Share on other sites More sharing options...
per1os Posted June 15, 2007 Share Posted June 15, 2007 no pros here to answer that question? Apparently not. At anyrate you are doing it wrong. I would suggest looking into Pagination, a nice tutorial is on this site. The LIMIT function usage you are doing is incorrect. LIMIT HOWMANY, START So if you wanted to limit it to 5 images starting at 20 it would look like so: LIMIT 5,20 http://dev.mysql.com/doc/refman/5.0/en/select.html Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275376 Share on other sites More sharing options...
corillo181 Posted June 15, 2007 Author Share Posted June 15, 2007 that's the problem that i'm working on a gallery the number are always going to be changing, i had it before but someone deleted my code by mistake. here is a website of what i have in mind. http://www.lostraficante.com/user/displayimage.php?album=138&pos=2 see there is the 2 past picture and the 2 next to come and the current in the middle and they not by order of numbers they are just by > or < the middle picture. Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275378 Share on other sites More sharing options...
Wildbug Posted June 15, 2007 Share Posted June 15, 2007 (SELECT * FROM tra_gallery_photo WHERE album_id=xx ORDER BY ordercol LIMIT 2) UNION (SELECT * FROM tra_gallery_photo WHERE album_id=xx ORDER BY ordercol DESC LIMIT 2) ORDER BY ordercol This will give you the first two and last two rows where "ordercol" is the column by which you are ordering the results. Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275417 Share on other sites More sharing options...
corillo181 Posted June 15, 2007 Author Share Posted June 15, 2007 the result is not even close to what the website looks like above Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275449 Share on other sites More sharing options...
Wildbug Posted June 15, 2007 Share Posted June 15, 2007 Oh, sorry, I misread your post. You should probably be doing it like has been already suggested above, using "....LIMIT offset, 5". Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275467 Share on other sites More sharing options...
corillo181 Posted June 15, 2007 Author Share Posted June 15, 2007 i did tried it that way, but when i click on a image they disappear one by one until there i only one left. Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275472 Share on other sites More sharing options...
Wildbug Posted June 15, 2007 Share Posted June 15, 2007 Well, then troubleshoot your code as there is a bug somewhere in its logic. Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275480 Share on other sites More sharing options...
corillo181 Posted June 15, 2007 Author Share Posted June 15, 2007 i guess.. Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275547 Share on other sites More sharing options...
corillo181 Posted June 16, 2007 Author Share Posted June 16, 2007 i went with this but if anyone ever finds better solution let me know. $selectless=mysql_query("SELECT * FROM tra_gallery_photo WHERE album_id='$album' AND photo_id<'$photo_id' AND photo_id>'$photo_id'-3 LIMIT 3")or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/55624-php-query-asc-desc/#findComment-275615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.