jck Posted July 14, 2007 Share Posted July 14, 2007 my previous topic was so confusing so i decided to start a new topic there is a table jokes and 1 feild is for category i need next button to go to the next joke in the same category(by id) and previous to the previous one im not getting an idea to do this so can anyone tell me how to do this Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 14, 2007 Share Posted July 14, 2007 Think about it logically. What you want (for the previous) is the record where category is your category AND the record is the HIGHEST of all records LOWER than the present one. Here's a pseudo-query to illustrate SELECT * from your_table WHERE category = whatever AND id < current_id ORDER by id DESC LIMIT 1 Quote Link to comment Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 this i figured out too if u see the other post but after the query pls go on?? Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 14, 2007 Share Posted July 14, 2007 this i figured out too if u see the other post but after the query pls go on?? Great, so why didn't you explain that to people who read this thread? If it was already resolved in your previous thread but you needed more help, why didn't you continue with the previous thread? Do you mean, you don't know what to do with the query result? Aren't you looking for something to pass in a 'previous' link. Would the database id for the previous link be what you need? Quote Link to comment Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 exactly i dont know what to do to the query result i mean it must dedect which one im on in the table and see which is prev to that and which is next that i dont know how to do Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 14, 2007 Share Posted July 14, 2007 exactly i dont know what to do to the query result i mean it must dedect which one im on in the table and see which is prev to that and which is next that i dont know how to do 'It' was exactly what the pseudo-query I gave you is written to determine. If you know how to get a joke out of your database, you already know how to handle a query result don't you? Quote Link to comment Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 im sorry i didnt understand what ur saying Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 14, 2007 Share Posted July 14, 2007 im sorry i didnt understand what ur saying me too. If you have a question, try to frame it coherently and with enough context so anybody reading it will understand what you are asking about. I gave you a prototype query for determining the previous record that matched a category. Did you try it? What did it show? How did you incorporate it into your code - which so far hasn't even appeared in this thread. Quote Link to comment Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 oops im sorry i didnt know properly about the limit function i was thinking how to list all and detect or something like that sorry for troubling you i guess it will surely work but ill mark it resolved after i test it Quote Link to comment Share on other sites More sharing options...
jck Posted July 14, 2007 Author Share Posted July 14, 2007 thanks i did it Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 14, 2007 Share Posted July 14, 2007 Maybe you want to post the code that works so other members can see the solution. Also, please mark this thread as SOLVED. Quote Link to comment Share on other sites More sharing options...
jck Posted July 15, 2007 Author Share Posted July 15, 2007 Working code <? $rnext = mysql_query("SELECT * from dd_items WHERE ItemCategory = '$a1[itemCategory]' AND ItemID < '$ItemID' AND ItemStatus = 'approved' ORDER by ItemID DESC LIMIT 1"); $rownext = mysql_fetch_array($rnext); if ($rownext['ItemID'] != 0) { $next = $rownext['ItemID']; } else { $next = $ItemID; } $rprev = mysql_query("SELECT * from dd_items WHERE ItemCategory = '$a1[itemCategory]' AND ItemID > '$ItemID' AND ItemStatus = 'approved' ORDER by ItemID DESC LIMIT 1"); $rowprev = mysql_fetch_array($rprev); if ($rowprev['ItemID'] != 0) { $prev = $rowprev['ItemID']; } else { $prev = $ItemID; } ?> <a href="/view.php?ItemID=<?=$prev?>"><img style="border: 0px solid ; width: 50px; height: 50px;" alt="Previous Joke in this category" src="images/prev.gif"></a><a href="view.php?ItemID=<?=$next?>"><img style="border: 0px solid ; width: 50px; height: 50px;" alt="Next Joke in this category" src="images/next.gif"></a> 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.