Log in

View Full Version : pagination



panassonic
04-13-2010, 12:35 PM
Hi!
I am a beginner in PHP and I have the following problem: site for movies with categories: comedy, horror, action and so on... the code for displaying the results is the same for all of the genres and I make the following:
<a href="movies.php?category=comedy">COMEDY</a>
and then:
$index = (preg_match("//", $_GET['category'])) ? $_GET['category'] : 0;
$sql = "SELECT * FROM movies WHERE category = '$index' ORDER BY movID DESC";
It's okay so far BUT... for every genre, I have and pagination, and when try to go the next page, consider page 2 for genre comedy just nothing... I can't explain exactly... I just want to ask you some advise how to reuse the same code for all genres, and the pagination to work properly, some good tutorial or something else... if somebody is interesting in that I can show him the code... the site I am making is just for my personal training...
PS: My english is nor very good, sorry about that :) please in the beginning of your answer rate my level of english(1-10) thanks :rolleyes:

djr33
04-13-2010, 05:49 PM
Your English is fine.


I suggest using a loop like this:

$genres = ('1','2','3',....,'X');
foreach ($genres as $genre) {
//insert your code here
}

Also, you could use a variable called $genre and use input (like .../page.php?genre=action => $_GET['genre'] ), then use that information.

Can you link to your page or how you want it to look? There are a lot of ways to do pagination.

panassonic
04-14-2010, 10:23 AM
Thanks djr33, I will try by that way, I hope it will work :)