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
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

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.