Hi All!
I have 3 tables:
Category, Project , Entry .
Category have CatId as PK
Project have ProId as Pk and CatId as FK
Entry have EntId as Pk, ProId as Fk and Catd as FK
How to make a Next Prev links that if you are in
view.php?CatId=11&ProId=22&EntId=111
when you choose next, it goes and check who is next record from same category and same project and display,e.g.
view.php?CatId=11&ProId=22&EntId=112
if there is no entry in that project go to next project , first entry, then dispay entry,
view.php?CatId=11&ProId=23&EntId=113
and if there is no project in that category display next category with first project and first entry.
view.php?CatId=12&ProId=24&EntId=114
thanks.
Complex next prev (not too complex)
Moderator: General Moderators
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Code: Select all
echo '<a href="view.php?CatId=11&ProId=22&EntId='.$_GET['EntId']+1.'">next</a>'Code: Select all
echo '<a href="view.php?CatId=11&ProId=22&EntId='.$_GET['EntId']-1.'">prev</a>'Cheers,
Kieran
Kieran Huggins wrote:Code: Select all
echo '<a href="view.php?CatId=11&ProId=22&EntId='.$_GET['EntId']+1.'">next</a>'Code: Select all
echo '<a href="view.php?CatId=11&ProId=22&EntId='.$_GET['EntId']-1.'">prev</a>'
Kieran, thanks for reply!
I know what you mean but ,its not that easy,
how to to know if there is no more entry in that project and there is no more projects in that category
so I should have like this:
<| < entry 3 of 3 > |>
I should count how many entries are in a project then display , if there are no more entries , like 3 of 3 check next project if have entries, if yes, count how many, and display, if next project doesnt exist change category, and if latest category latest project and latest entry go to first.
Its kinda complex. thats why I decide to ask experts.
I know what you mean but ,its not that easy,
how to to know if there is no more entry in that project and there is no more projects in that category
so I should have like this:
<| < entry 3 of 3 > |>
I should count how many entries are in a project then display , if there are no more entries , like 3 of 3 check next project if have entries, if yes, count how many, and display, if next project doesnt exist change category, and if latest category latest project and latest entry go to first.
Its kinda complex. thats why I decide to ask experts.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
I know, I know... I felt a little dirty hitting submitThe Ninja Space Goat wrote:![]()
input filtering!!
My *real* solution would be to retrieve all distinct CatId, ProId, and EntId's from the database and drop them in the $_SESSION array. then you can simply link to the next record by appending ?next[entity] to the URL.
Code: Select all
// I assume $EntId is the variable with the current EntId in it.
$EntIdPos = array_search($EntId,$_SESSION['EntId']);
if(isset($_GET['next']['entity']) && isset($_SESSION['EntId'][$EntIdPos+1])) $EntId = $_SESSION['EntId'][$EntIdPos+1];
if(isset($_GET['prev']['entity']) && isset($_SESSION['EntId'][$EntIdPos-1])) $EntId = $_SESSION['EntId'][$EntIdPos-1];
// carry on...Eventually, you'll want to take a look at "clean URLs" and mod_rewrite. But that may be a little while in your future.
Cheers,
Kieran