Jump to content

[SOLVED] going to next one of a category


jck

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/59966-solved-going-to-next-one-of-a-category/
Share on other sites

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

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?

 

 

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?

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.

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.