kirk112 Posted January 10, 2007 Share Posted January 10, 2007 Really stumped on how to acheive this....I have a form in which people can search the database for items and when they click on the item it takes them to the item details page on the bottom of this page I want to have previous and next item.How can I get the pervious and next item_id passed to this page or if I run the query again on the details page how can I get the pervious and next item from the results?Hope this makes sense (does not to me) I can't seem to get my head around this....Thanks for your help!!!! Quote Link to comment Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 theres lots of tutorials about pagination here :-)not tested... but should work...[code]$topallowed=10;if(empty($_GET[page])) $topfile=0;else $topfile=$_GET[page];$topallowed=$topallowed+$page;$result=mysql_query("SELECT * FROM table LIMIT $topfile, $topalllowed");while($row=mysql_fetch_array($result)){}echo '<a href="?page='.$page-1.'">prev</a>';echo '<a href="?page='.$page+1.'">next</a>';[/code]just for ideas... Quote Link to comment Share on other sites More sharing options...
kirk112 Posted January 10, 2007 Author Share Posted January 10, 2007 Hi Taith, Thanks for your response - I have managed to do the pagination on the search page - with a very very helpful tutorial of this site.I will try to explain a little better...on the search page when the user click on a product it passes the item_id and the search string to the item details page, on the item details page it displays the details and an option to go back to the search (which is fine) but instead of going back to the search page I want to be able to have previous and next buttons so that they can go to the next item with in the search that they previously have done. But I can I find what the pervious and next items are?? Quote Link to comment Share on other sites More sharing options...
taith Posted January 10, 2007 Share Posted January 10, 2007 personally... if it were me, i like functions... i'd do it this way....[code]function get_itemname($id){ if(!isset($allitemnames[$id])){ $result=mysql_query("SELECT * FROM items WHERE `id`='$id' LIMIT 1"); $row=mysql_fetch_array($result); $allitemnames[$id]=$row[name]; } return $allitemnames[$id];}[/code]then wherever you want an item name...just...[code]echo get_itemname(1);echo get_itemname($page-1);echo get_itemname($page+1);[/code]or to that effect :-) Quote Link to comment Share on other sites More sharing options...
kirk112 Posted January 10, 2007 Author Share Posted January 10, 2007 Thanks again TaithIf I use your function I still don't know what the previous and next result would be, as there are about 300 result produced on each search and the item_id's are not incremental because the search would filter out some of the item.on the search result page it displaysitem_id item_name item_price 1 test 33 4 test2 54 5 test3 88 8 test66 99first page 2 ,3, 4, 5, 6, last page etcIf I click on item_id 5 on the item details page it passes the item_id(5) and the search string eg(price less than <100) On the items details page I have:item details - test3 price 88back to results (which take me back to the search details page)What I need is a next button which would take me to item_8 and and previous button which would take me to item_4, how I can get item4 and item8 passed to the item details page to that I can use these variable to create the link to these different items page.Thanks for your patience Quote Link to comment Share on other sites More sharing options...
snivek Posted January 10, 2007 Share Posted January 10, 2007 I have a function that does this...It's not the most elegant piece of code I have written but it works. I did this for viewing images one at a time from an album.[code]<?phpwhile($row = mysql_fetch_assoc($result)){ If ($row['image_id'] == $image_id) { $previous_image = $tmpPrev; $image_name = $row['image_file_name']; $bool_next = TRUE; }elseif ($bool_next === TRUE) { $next_image = $row['image_id']; $bool_next = FALSE; }else { $tmpPrev = $row['image_id']; } $i=$i+1;?>}[/code] Quote Link to comment 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.