Jump to content

Pagination along with criteria on the results


Ugluth

Recommended Posts

Hello I want to create a page where the movies of my database will be available for view. I have added a drop down box where the user can select one parameter to categorize the results, like release date, category etc..

 

I used to use a pagination script which really worked perfect, but I'm having some problems right now. The dropdown boxes keep the values they have on each postback of that form. The problem is that if a page has more results, and you press the next page link, you get the results from a "new" query, instead of the remaining results of that query. That probably is hard to understand, so i will paste some of my code.

 

The pagination script i am using is http://phpsense.com/php/php-pagination-script.html. Ok and here's the code i have written.

<form action="view_movies.php" method="post">
		<label for="picker">Please select how to display movies.</label><br />
//This is the list where the user chooses on what to categorize the results.
		<select name="picker" id="picker">
			<option <?php if(isset($picker) && $picker === "category") { echo "selected"; } ?> value="category">Category</option>
			<option <?php if(isset($picker) && $picker === "release") { echo "selected"; } ?> value="release">Release Date</option>
			<option <?php if(isset($picker) && $picker === "mov_med") { echo "selected"; } ?> value="mov_med">Movie Medium</option>
			<option <?php if(isset($picker) && $picker === "rent_time") { echo "selected"; } ?> value="rent_time">Rental Period</option>
			<option <?php if(isset($picker) && $picker === "price") { echo "selected"; } ?> value="price">Price</option>
		</select><br />
<?php if (isset($picker)) {
//This is the second drop down box to show once the user has made a choise.
			switch ($picker) {
				case "category": ?>
        		<select name="category" id="category">
		    		<option value="">Select a category</option>
		    	 <?php	while($row_cat = mysql_fetch_row($result_category)) {  ?>
		    		<option <?php if ($parameter == $row_cat[0]) { echo "selected"; } ?> value="<?php echo $row_cat[0]; ?>"><?php echo $row_cat[1]; ?></option>
		    	 <?php } ?>
		   	 </select> <?php
        		break;
        		case "release": ?>
						<select name="release" id="release">
							<option value="">Select a year</option>
							<?php	while($row_release = mysql_fetch_row($result_release_date)) {  ?>
		    			<option <?php if ($parameter == $row_release[0]) { echo "selected"; } ?> value="<?php echo $row_release[0]; ?>"><?php echo $row_release[0]; ?></option>
		    			<?php } ?>
						</select><?php
						break;
        	case "mov_med": ?>
        	<select name="medium" id="medium">
		    		<option value="">Select a medium</option>
		    	<?php	while($row_med = mysql_fetch_row($result_mov_med)) {  ?>
		    	<option <?php if ($parameter == $row_med[0]) { echo "selected"; } ?> value="<?php echo $row_med[0]; ?>"><?php echo $row_med[1]; ?></option>
		    <?php } ?>
		    </select><?php
		    break;
		   	case "rent_time": ?>
		   	<select name="period" id="period">
		    		<option value="">Select a period</option>
		    	<?php	while($row_per = mysql_fetch_row($result_period)) {  ?>
		    	<option <?php if ($parameter == $row_per[0]) { echo "selected"; } ?> value="<?php echo $row_per[0]; ?>"><?php echo $row_per[1]; ?></option>
		    <?php } ?>
		    </select><?php
		   	break;
		   	case "price": ?>
		   	<select name="price" id="price">
		    		<option value="">Select a price</option>
		    	<?php	while($row_per = mysql_fetch_row($result_period)) {  ?>
		    	<option <?php if ($parameter == $row_per[0]) { echo "selected"; } ?> value="<?php echo $row_per[0]; ?>"><?php echo $row_per[2]; ?></option>
		    <?php } ?>
		    </select><?php
		   	break;
			}
		}
	?>
		<input type="submit" value="go">
	</form>

 

After having the selection of the user, i modify my query with some elseif's according to what the user has picked. That all works fine so i wont make this post even longer.

 

I have also read the pagination tutorial on the site, which was really helpful, but I'm not really sure how to go about what i want to do. First of all, is this way I'm doing things correct? Or is there another way that is a lot simpler? And my second question is if i should embed what the user has chosen on these menus on the link for the pagination.

 

Please advice me what to do, and sorry for the long post.

Link to comment
Share on other sites

Well yes the problem lies in the next button as well for sure, the only way i can think i can fix this is by adding the values of the 2 dropdown boxes on each navigation link. But i thought i'd post this here, because this isn't something new that has never been seen before, many sites allow you to do these 2 things together.

 

The navigation for the pages at the moment is handled by the pagination script as i said. I will try to make it manually, or change the code a bit on the script to try to embed the values from the 2 dropdowns on each navigation link.

 

If someone has a better solution, please guide me the correct way :)

Link to comment
Share on other sites

How about adding some javascript there? Make your links so that they call a simple javascript function which will insert a page number in your form. (Into hidden field) And then make form.submi() which is kind of the same as clicking a link?

Link to comment
Share on other sites

Hi, My Problem is solved by :

$pager = new PS_Pagination($link,$query,2,1,"param1=$valu1&param2=$valu2");

 

instead of valu# ,set your var and before and after code(s), control them.

in :..MATCH(keywords) AGAINST("something" IN BOOLEAN MODE) ,it good but in LIKE becare!TNX.

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.