zero118 Posted August 30, 2006 Share Posted August 30, 2006 I have a problem that I can't seem to wrap my mind around. I've tried long and hard the last few days to figure out how to wrap pagination around the small site search engine I've written and I think it needs an outside, personal/more professional touch. So if anyone can help me with my actual code instead of tutorials that aren't built around my situation it would be greatly appriciated.[code]<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="240" align="left" valign="top"><img src="img/pd-search.jpg" width="230" height="160" style="padding-right:6px;" /><br /> <br /> <br /> <br /> <a href="<?=$siteadd?>"><img src="img/page-logo.jpg" width="230" height="108" border="0" /></a></td> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><strong> <?php if ($go){ // If form submitted // Calculate the search range for PSI if ($psi != ""){ if ($psi < 1400){ $psi01 = $psi; $psi02 = ($psi * 1.19); } else if ($psi >= 1400){ $psi01 = $psi; $psi02 = ($psi * 1.21); } } else if (!$psi or $psi == ""){ $psi01 = 0; $psi02 = 9999999; } // Calculate the search range for GPM if ($gpm != ""){ $gpm1 = $gpm; $gpm2 = ($gpm * 1.2); } else if (!$gpm or $gpm == ""){ $gpm1 = 0; $gpm2 = 9999999; } // Send information and call the results result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod); }// If form has not been submittedif (!$go == '' or !$go) { ?> </strong> <form action="index.php?p=srchprod" method="post"> <table width='405' height="285" border='0' cellpadding='3' cellspacing='0' style="background:url(<?=$siteadd?>/img/search-back.jpg); background-position:left; background-repeat:no-repeat; background-color:#000000"> <tr> <td width="512" height="22" style="background:url(<?=$siteadd?>/menus/images/newline.gif);"><strong><font color="#FFFFFF">Search</font></strong></td> </tr> <tr> <td height="260" align="left" valign="middle" ><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="37%" height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="psi" type="text" id="psi" style="width:120px;" onkeypress="return numeralsOnly(event)" value="<?=$psi?>" /> </strong></td> <td width="63%" height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Pressure per Square Inch <br /> <font size="1">(searches using max PSI) </font></font></strong></td> </tr> <tr> <td height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="gpm" type="text" id="gpm" style="width:120px;" onkeypress="return numeralsOnly(event)" value="<?=$gpm?>" /> </strong></td> <td height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Flow Rate<br /> <font size="1">(searches using max GPM) </font></font></strong></td> </tr> <tr> <td height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="model" type="text" id="mod" style="width:120px;" value="<?=$mod?>" /> </strong></td> <td height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Pump Model Number <br /> <font size="1">(i.e. KD-12 will display all pumps beginning with that) </font></font></strong></td> </tr> <tr> <td height="45" align="right" style="padding-right:10px;"><font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif"> <label> <font size="2">Continuous Duty<font color="#FFFFFF" face="Arial, Helvetica, sans-serif"> <input name="use01" type="radio" value="Continuous" <?php if ($use01 != "Intermittent") { echo "checked=checked";} ?> /> </font></font></label> <font size="2"> <br /> <label> Intermittent Duty<font color="#FFFFFF" face="Arial, Helvetica, sans-serif"> <input name="use01" type="radio" value="Intermittent" <?php if ($use01 == "Intermittent") { echo "checked=checked";} ?> /> </font></label> </font> </font></td> <td height="45"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Usage<br /> </font></strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><font size="1"><strong>(Continuous: more than 6 hrs/day to 14<br /> hrs/day. fully loaded ) <br /> </strong></font><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><font size="1"><strong>(Intermittent: less than 6 hrs/day, loaded no<br /> more than 15 min. every hr.)</strong></font></font></font></td> </tr> <tr> <td align="center"><strong> <input type="submit" name="go" value="Search" style="width:120px;" /> </strong></td> <td> </td> </tr> </table></td> </tr> </table> <strong><br /> </strong> </form> <strong> <?php } // Show resultsfunction result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod){include('db.php'); if ($model != "") {// Query if Model has been searched for$query_mem_1 = "SELECT * FROM `$pump_database_table` WHERE ((`psi1` > $psi01 AND `psi1` < $psi02) OR(`psi2` > $psi01 AND `psi2` < $psi02) OR(`psi3` > $psi01 AND `psi3` < $psi02) OR(`psi4` > $psi01 AND `psi4` < $psi02) OR(`psi5` > $psi01 AND `psi5` < $psi02) OR(`psi6` > $psi01 AND `psi6` < $psi02) OR(`psi7` > $psi01 AND `psi7` < $psi02)) AND((`maxflow` > $gpm1 AND `maxflow` < $gpm2) OR(`flow2` > $gpm1 AND `flow2` < $gpm2) OR(`flow3` > $gpm1 AND `flow3` < $gpm2) OR(`flow4` > $gpm1 AND `flow4` < $gpm2) OR(`flow5` > $gpm1 AND `flow5` < $gpm2) OR(`flow6` > $gpm1 AND `flow6` < $gpm2) OR(`flow7` > $gpm1 AND `flow7` < $gpm2)) AND(`use` = '$use01') AND `model` LIKE CONVERT ( _utf8 '%$mod%' USING latin1 ) COLLATE latin1_swedish_ci ORDER BY maxflow ASC";}else if (!$mod or $mod == ""){// Query if Model was not searched for$query_mem_1 = "SELECT * FROM `$pump_database_table` WHERE ((`psi1` > $psi01 AND `psi1` < $psi02) OR(`psi2` > $psi01 AND `psi2` < $psi02) OR(`psi3` > $psi01 AND `psi3` < $psi02) OR(`psi4` > $psi01 AND `psi4` < $psi02) OR(`psi5` > $psi01 AND `psi5` < $psi02) OR(`psi6` > $psi01 AND `psi6` < $psi02) OR(`psi7` > $psi01 AND `psi7` < $psi02)) AND((`maxflow` > $gpm1 AND `maxflow` < $gpm2) OR(`flow2` > $gpm1 AND `flow2` < $gpm2) OR(`flow3` > $gpm1 AND `flow3` < $gpm2) OR(`flow4` > $gpm1 AND `flow4` < $gpm2) OR(`flow5` > $gpm1 AND `flow5` < $gpm2) OR(`flow6` > $gpm1 AND `flow6` < $gpm2) OR(`flow7` > $gpm1 AND `flow7` < $gpm2)) AND(`use` = '$use01') ORDER BY maxflow ASC";}$mem_1 = mysql_query($query_mem_1, $connection) or die(mysql_error());$row_mem_1 = mysql_fetch_assoc($mem_1);$numOfRows = mysql_num_rows($mem_1);// No resultsif ($numOfRows == 0){?> </strong> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td background="menus/images/newline.gif"><strong><font color="#FFFFFF">Results: No Matches</font></strong></td> </tr> <tr> <td height="70" align="left" valign="top" class="prod"><strong>We're sorry. There were no matches for the search criteria you specified. Please try again.</strong></td> </tr> </table> <strong><br /> <?php }// The results if ($mem_1){ $numOfRows = mysql_num_rows ($mem_1); for ($i = 0; $i < $numOfRows; $i++){ $id = mysql_result ($mem_1, $i, "id"); $model = mysql_result ($mem_1, $i, "model"); $img = mysql_result ($mem_1, $i, "img"); $type = mysql_result ($mem_1, $i, "type"); $psi1 = mysql_result ($mem_1, $i, "psi1"); $maxflow = mysql_result ($mem_1, $i, "maxflow"); $use = mysql_result ($mem_1, $i, "use"); $cylinder = mysql_result ($mem_1, $i, "cylinder"); // conver numbers to words / cylindersif ($cylinder == '1'){ $cylinder = "Simplex"; }if ($cylinder == '2'){ $cylinder = "Duplex"; }if ($cylinder == '3'){ $cylinder = "Triplex"; }if ($cylinder == '5'){ $cylinder = "Quintuplex"; }if ($cylinder == '6'){ $cylinder = "Sextuplex"; } ?> </strong> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td colspan="2" background="menus/images/newline.gif"><strong><font color="#FFFFFF"> <?=$model?> </font></strong></td> </tr> <tr> <td width="186" height="70" align="left" valign="top" class="prod"><strong> <?=$use?> Duty<br /> <?=$cylinder?> <?=$type?> Pump <br /> Max PSI: <?=$psi1?> PSI<br /> Max Flow Rate: <?=$maxflow?> GPM</strong></td> <td width="180" height="70" align="right" valign="bottom" class="prod"><strong><a href='index.php?p=pmp&pid=<?=$id?>' class="prod">See this pump</a><br /> <?php if ($img != "img/pp/") { ?> <a href='pd.php?pid=<?=$id?>' onclick="NewWindow(this.href,'pd','690','420','no','center');return false" onfocus="this.blur" class="prod">View dimensions</a><br /> <?php } ?> <a href='calc.php' onclick="NewWindow(this.href,'pd','690','450','yes','center');return false" onfocus="this.blur" class="prod">View Pump Calculations</a></strong></td> </tr> </table> <br /> <?php } } } ?> </td> </tr> </table></td> </tr></table></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/ Share on other sites More sharing options...
sasa Posted August 30, 2006 Share Posted August 30, 2006 add [code]if (isset($_POST)) foreach ($_POST as $k => $v) $$k = $v;[/code]after 1st '<?php' (line 12) Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-83082 Share on other sites More sharing options...
zero118 Posted August 30, 2006 Author Share Posted August 30, 2006 Umm, thanks for the reply but I don't think that has anything to do with my issue... Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-83088 Share on other sites More sharing options...
HeyRay2 Posted August 30, 2006 Share Posted August 30, 2006 Based on your code, I'm not seeing anything in your situation that the numerous pagination tutorials around couldn't handle.The only thing I'm seeing that some tutorials may not cover is carrying over your search criteria to each result page, which is pretty straightforward to implement.Let's start with your first block of PHP, which checks if the search form was submitted. We'll add code to check for a [b]$page[/b] variableand set a variable to limit results per page ([b]$max_results[/b]):[code] <?php if ($go){ // If form submitted // Check if a page value was passed // if not, set the default page (1) if( isset($_POST['page']) && !empty($_POST['page']) && ctype_digit($_POST['page']) ){ $page = $_POST['page']; } else { $page = 1; } // Set the maximum results per page $max_results = 10; // Calculate the search range for PSI if ($psi != ""){ if ($psi < 1400){ $psi01 = $psi; $psi02 = ($psi * 1.19); } else if ($psi >= 1400){ $psi01 = $psi; $psi02 = ($psi * 1.21); } } else if (!$psi or $psi == ""){ $psi01 = 0; $psi02 = 9999999; } // Calculate the search range for GPM if ($gpm != ""){ $gpm1 = $gpm; $gpm2 = ($gpm * 1.2); } else if (!$gpm or $gpm == ""){ $gpm1 = 0; $gpm2 = 9999999; } // Send information and call the results result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results); } // If form has not been submitted else { ?>[/code]I changed your [b]result()[/b] function to include the current page and the maximum results per page variablesin it's argument list. This will allow that function to do you pagination.You'll also notice I changed this:[code=php:0]// If form has not been submittedif (!$go == '' or !$go) { ?>[/code]to this:[code=php:0]// If form has not been submittedelse {[/code]Since you've already checked if [b]$go[/b] was true, there's no need to check any other condition,because if [b]$go[/b] is not [b]TRUE[/b], then it has to be [b]FALSE[/b].Next, I'll go over changes within your [b]result()[/b] function:[code=php:0] // Show results function result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results) { include('db.php'); // ... YOUR QUERY BUILDING CODE WAS HERE // ... // ... // Fetch a count of all results $mem_1 = mysql_query($query_mem_1, $connection) or die(mysql_error()); $numOfRows = mysql_num_rows($mem_1); // No results if ($numOfRows == 0){ // ... "NO RESULTS" PRINTED OUT HERE // ... // ... } else { // Determine the number of pages $num_pages = ceil($numOfRows / $max_results); // Determine the starting result to print $start_result = ($page * $max_results) - $max_results; // Append to our query with our result limit $query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results.""; // Query for our current page of results $mem_1_limit = mysql_query($query_mem_1_limit, $connection) or die(mysql_error()); $row_mem_1_limit = mysql_fetch_assoc($mem_1_limit); // Print The results $numOfPageRows = mysql_num_rows($mem_1_limit); for ($i = 0; $i < $numOfPageRows; $i++){ $id = mysql_result ($mem_1, $i, "id"); $model = mysql_result ($mem_1, $i, "model"); $img = mysql_result ($mem_1, $i, "img"); $type = mysql_result ($mem_1, $i, "type"); $psi1 = mysql_result ($mem_1, $i, "psi1"); $maxflow = mysql_result ($mem_1, $i, "maxflow"); $use = mysql_result ($mem_1, $i, "use"); $cylinder = mysql_result ($mem_1, $i, "cylinder"); // conver numbers to words / cylinders if ($cylinder == '1'){ $cylinder = "Simplex"; } if ($cylinder == '2'){ $cylinder = "Duplex"; } if ($cylinder == '3'){ $cylinder = "Triplex"; } if ($cylinder == '5'){ $cylinder = "Quintuplex"; } if ($cylinder == '6'){ $cylinder = "Sextuplex"; } // ... "RESULTS" PRINTED HERE // ... // ... } // Start pagination ?> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td> <?php // Loop to print a button for each page of results for($j = 1;$j <= $num_pages;$j++){ // Check if we are printing the current page // we won't make it an active button $disabled = ($j == $page) ? "DISABLED" : NULL; ?> <form action="index.php?p=srchprod" method="post"> <input type="hidden" name="psi" id="psi" value="<?=$psi?>" /> <input type="hidden" name="gpm" id="gpm" value="<?=$gpm?>" /> <input type="hidden" name="use01" id="use01" value="<?=$use01?>" /> <input type="hidden" name="mod" id="mod" value="<?=$mod?>" /> <input type="hidden" name="page" id="page" value="<?=$j?>" /> <input type="submit" name="go" id="go" value="<?=$j?>" <?=$disabled?> /> </form> <?php } } ?> </td> </td> </table>[/code]I commented out some of your code that didn't change, like code that printed the results and such.You'll notice that after building the query, I added code that calculates how many pages of result there are bydividing the total result rows and diving by the results per page. I use the [b]ceil()[/b] function to round upif a get a decimal value (i.e 10 results @ 3 per page = 3.3 pages. You would need to 4 page links to show all results)We then add a "LIMIT" line to your query, which will only pull a certain number of results, starting at the correct result[code=php:0]// Determine the starting result to print$start_result = ($page * $max_results) - $max_results;// Append to our query with our result limit$query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results."";// Query for our current page of results$mem_1_limit = mysql_query($query_mem_1_limit, $connection) or die(mysql_error());$row_mem_1_limit = mysql_fetch_assoc($mem_1_limit);[/code]After printing the results, we print a small form for each page button. This will ensure that your search values get passedto each result page, so your query will pull the right values. Each button is named [b]go[/b], so that your code you hadto check if the form was submitted will be executed for each page link.The full modified code is below:[code]<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="240" align="left" valign="top"><img src="img/pd-search.jpg" width="230" height="160" style="padding-right:6px;" /><br /> <br /> <br /> <br /> <a href="<?=$siteadd?>"><img src="img/page-logo.jpg" width="230" height="108" border="0" /></a></td> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><strong> <?php if ($go){ // If form submitted // Check if a page value was passed // if not, set the default page (1) if( isset($_POST['page'] && !empty)$_POST['page'] && ctype_digit($_POST['page']) ){ $page = $_POST['page']; } else { $page = 1; } // Set the maximum results per page $max_results = 10; // Calculate the search range for PSI if ($psi != ""){ if ($psi < 1400){ $psi01 = $psi; $psi02 = ($psi * 1.19); } else if ($psi >= 1400){ $psi01 = $psi; $psi02 = ($psi * 1.21); } } else if (!$psi or $psi == ""){ $psi01 = 0; $psi02 = 9999999; } // Calculate the search range for GPM if ($gpm != ""){ $gpm1 = $gpm; $gpm2 = ($gpm * 1.2); } else if (!$gpm or $gpm == ""){ $gpm1 = 0; $gpm2 = 9999999; } // Send information and call the results result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results); } // If form has not been submitted else { ?> </strong> <form action="index.php?p=srchprod" method="post"> <table width='405' height="285" border='0' cellpadding='3' cellspacing='0' style="background:url(<?=$siteadd?>/img/search-back.jpg); background-position:left; background-repeat:no-repeat; background-color:#000000"> <tr> <td width="512" height="22" style="background:url(<?=$siteadd?>/menus/images/newline.gif);"><strong><font color="#FFFFFF">Search</font></strong></td> </tr> <tr> <td height="260" align="left" valign="middle" ><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="37%" height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="psi" type="text" id="psi" style="width:120px;" onkeypress="return numeralsOnly(event)" value="<?=$psi?>" /> </strong></td> <td width="63%" height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Pressure per Square Inch <br /> <font size="1">(searches using max PSI) </font></font></strong></td> </tr> <tr> <td height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="gpm" type="text" id="gpm" style="width:120px;" onkeypress="return numeralsOnly(event)" value="<?=$gpm?>" /> </strong></td> <td height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Flow Rate<br /> <font size="1">(searches using max GPM) </font></font></strong></td> </tr> <tr> <td height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="model" type="text" id="mod" style="width:120px;" value="<?=$mod?>" /> </strong></td> <td height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Pump Model Number <br /> <font size="1">(i.e. KD-12 will display all pumps beginning with that) </font></font></strong></td> </tr> <tr> <td height="45" align="right" style="padding-right:10px;"><font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif"> <label> <font size="2">Continuous Duty<font color="#FFFFFF" face="Arial, Helvetica, sans-serif"> <input name="use01" type="radio" value="Continuous" <?php if ($use01 != "Intermittent") { echo "checked=checked";} ?> /> </font></font></label> <font size="2"> <br /> <label> Intermittent Duty<font color="#FFFFFF" face="Arial, Helvetica, sans-serif"> <input name="use01" type="radio" value="Intermittent" <?php if ($use01 == "Intermittent") { echo "checked=checked";} ?> /> </font></label> </font> </font></td> <td height="45"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Usage<br /> </font></strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><font size="1"><strong>(Continuous: more than 6 hrs/day to 14<br /> hrs/day. fully loaded ) <br /> </strong></font><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><font size="1"><strong>(Intermittent: less than 6 hrs/day, loaded no<br /> more than 15 min. every hr.)</strong></font></font></font></td> </tr> <tr> <td align="center"><strong> <input type="submit" name="go" value="Search" style="width:120px;" /> </strong></td> <td> </td> </tr> </table></td> </tr> </table> <strong><br /> </strong> </form> <strong> <?php // Show results function result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results) { include('db.php'); if ($model != "") { // Query if Model has been searched for $query_mem_1 = "SELECT * FROM `$pump_database_table` WHERE ( (`psi1` > $psi01 AND `psi1` < $psi02) OR (`psi2` > $psi01 AND `psi2` < $psi02) OR (`psi3` > $psi01 AND `psi3` < $psi02) OR (`psi4` > $psi01 AND `psi4` < $psi02) OR (`psi5` > $psi01 AND `psi5` < $psi02) OR (`psi6` > $psi01 AND `psi6` < $psi02) OR (`psi7` > $psi01 AND `psi7` < $psi02)) AND ( (`maxflow` > $gpm1 AND `maxflow` < $gpm2) OR (`flow2` > $gpm1 AND `flow2` < $gpm2) OR (`flow3` > $gpm1 AND `flow3` < $gpm2) OR (`flow4` > $gpm1 AND `flow4` < $gpm2) OR (`flow5` > $gpm1 AND `flow5` < $gpm2) OR (`flow6` > $gpm1 AND `flow6` < $gpm2) OR (`flow7` > $gpm1 AND `flow7` < $gpm2)) AND (`use` = '$use01') AND `model` LIKE CONVERT ( _utf8 '%$mod%' USING latin1 ) COLLATE latin1_swedish_ci ORDER BY maxflow ASC"; } else if (!$mod or $mod == ""){ // Query if Model was not searched for $query_mem_1 = "SELECT * FROM `$pump_database_table` WHERE ( (`psi1` > $psi01 AND `psi1` < $psi02) OR (`psi2` > $psi01 AND `psi2` < $psi02) OR (`psi3` > $psi01 AND `psi3` < $psi02) OR (`psi4` > $psi01 AND `psi4` < $psi02) OR (`psi5` > $psi01 AND `psi5` < $psi02) OR (`psi6` > $psi01 AND `psi6` < $psi02) OR (`psi7` > $psi01 AND `psi7` < $psi02)) AND ( (`maxflow` > $gpm1 AND `maxflow` < $gpm2) OR (`flow2` > $gpm1 AND `flow2` < $gpm2) OR (`flow3` > $gpm1 AND `flow3` < $gpm2) OR (`flow4` > $gpm1 AND `flow4` < $gpm2) OR (`flow5` > $gpm1 AND `flow5` < $gpm2) OR (`flow6` > $gpm1 AND `flow6` < $gpm2) OR (`flow7` > $gpm1 AND `flow7` < $gpm2)) AND (`use` = '$use01') ORDER BY maxflow ASC"; } // Fetch a count of all results $mem_1 = mysql_query($query_mem_1, $connection) or die(mysql_error()); $numOfRows = mysql_num_rows($mem_1); // No results if ($numOfRows == 0){ ?> </strong> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td background="menus/images/newline.gif"><strong><font color="#FFFFFF">Results: No Matches</font></strong></td> </tr> <tr> <td height="70" align="left" valign="top" class="prod"><strong>We're sorry. There were no matches for the search criteria you specified. Please try again.</strong></td> </tr> </table> <strong><br /> <?php } else { // Determine the number of pages $num_pages = ceil($numOfRows / $max_results); // Determine the starting result to print $start_result = ($page * $max_results) - $max_results; // Append to our query with our result limit $query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results.""; // Query for our current page of results $mem_1_limit = mysql_query($query_mem_1_limit, $connection) or die(mysql_error()); $row_mem_1_limit = mysql_fetch_assoc($mem_1_limit); // Print The results $numOfPageRows = mysql_num_rows($mem_1_limit); for ($i = 0; $i < $numOfPageRows; $i++){ $id = mysql_result ($mem_1, $i, "id"); $model = mysql_result ($mem_1, $i, "model"); $img = mysql_result ($mem_1, $i, "img"); $type = mysql_result ($mem_1, $i, "type"); $psi1 = mysql_result ($mem_1, $i, "psi1"); $maxflow = mysql_result ($mem_1, $i, "maxflow"); $use = mysql_result ($mem_1, $i, "use"); $cylinder = mysql_result ($mem_1, $i, "cylinder"); // conver numbers to words / cylinders if ($cylinder == '1'){ $cylinder = "Simplex"; } if ($cylinder == '2'){ $cylinder = "Duplex"; } if ($cylinder == '3'){ $cylinder = "Triplex"; } if ($cylinder == '5'){ $cylinder = "Quintuplex"; } if ($cylinder == '6'){ $cylinder = "Sextuplex"; } ?> </strong> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td colspan="2" background="menus/images/newline.gif"><strong><font color="#FFFFFF"> <?=$model?> </font></strong></td> </tr> <tr> <td width="186" height="70" align="left" valign="top" class="prod"><strong> <?=$use?> Duty<br /> <?=$cylinder?> <?=$type?> Pump <br /> Max PSI: <?=$psi1?> PSI<br /> Max Flow Rate: <?=$maxflow?> GPM</strong></td> <td width="180" height="70" align="right" valign="bottom" class="prod"><strong><a href='index.php?p=pmp&pid=<?=$id?>' class="prod">See this pump</a><br /> <?php if ($img != "img/pp/") { ?> <a href='pd.php?pid=<?=$id?>' onclick="NewWindow(this.href,'pd','690','420','no','center');return false" onfocus="this.blur" class="prod">View dimensions</a><br /> <?php } ?> <a href='calc.php' onclick="NewWindow(this.href,'pd','690','450','yes','center');return false" onfocus="this.blur" class="prod">View Pump Calculations</a></strong></td> </tr> </table> <br /> <?php } // Start pagination ?> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td colspan="2" background="menus/images/newline.gif"><strong><font color="#FFFFFF"> <?php // Loop to print a button for each page of results for($j = 1;$j <= $num_pages;$j++){ // Check if we are printing the current page // we won't make it an active button $disabled = ($j == $page) ? "DISABLED" : NULL; ?> <form action="index.php?p=srchprod" method="post"> <input type="hidden" name="psi" id="psi" value="<?=$psi?>" /> <input type="hidden" name="gpm" id="gpm" value="<?=$gpm?>" /> <input type="hidden" name="use01" id="use01" value="<?=$use01?>" /> <input type="hidden" name="mod" id="mod" value="<?=$mod?>" /> <input type="hidden" name="page" id="page" value="<?=$j?>" /> <input type="submit" name="go" id="go" value="<?=$j?>" <?=$disabled?> /> </form> <?php } } ?> </td> </tr> </table></td> </tr></table></body></html>[/code]Good luck... ;) Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-83175 Share on other sites More sharing options...
zero118 Posted August 31, 2006 Author Share Posted August 31, 2006 Thanks for your help. I have a feeling this will work if I can just get past the syntax errors :) http://www.kerrpumps.com/index.php?p=srchprod3This shows an error on line 18 that I can't figure out.[CODE]if( isset($_POST['page'] && !empty)$_POST['page'] && ctype_digit($_POST['page']) ){ $page = $_POST['page']; } else { $page = 1; }ERROR:::::::Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in /home/kerrpump/public_html/srchprod3.php on line 18[/CODE]I already fixed a closing error with an if statement but this one is getting by me. Any changes you want to make to test it I can do live today to test it.THANKS!! Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-83484 Share on other sites More sharing options...
zero118 Posted August 31, 2006 Author Share Posted August 31, 2006 Anyone have some thoughts? :) Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-83509 Share on other sites More sharing options...
zero118 Posted August 31, 2006 Author Share Posted August 31, 2006 ANY ideas are welcome :P Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-83543 Share on other sites More sharing options...
sasa Posted August 31, 2006 Share Posted August 31, 2006 must be[code]if( isset($_POST['page']) && !empty($_POST['page']) && ctype_digit($_POST['page']) ){[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-83544 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 Thanks guys! Almost there!!!http://www.kerrpumps.com/index.php?p=srchprod3Check out the search results. (search for a psi of 1300 to get a good amount).Max_Results = 4 (to test the pagination)[code]<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="240" align="left" valign="top"><img src="img/pd-search.jpg" width="230" height="160" style="padding-right:6px;" /><br /> <br /> <br /> <br /> <a href="<?=$siteadd?>"><img src="img/page-logo.jpg" width="230" height="108" border="0" /></a></td> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><strong> <?php if ($go){ // If form submitted // Check if a page value was passed // if not, set the default page (1) if( isset($_POST['page']) && !empty($_POST['page']) && ctype_digit($_POST['page']) ){ $page = $_POST['page']; } else { $page = 1; } // Set the maximum results per page $max_results = 4; // Calculate the search range for PSI if ($psi != ""){ if ($psi < 1400){ $psi01 = $psi; $psi02 = ($psi * 1.19); } else if ($psi >= 1400){ $psi01 = $psi; $psi02 = ($psi * 1.21); } } else if (!$psi or $psi == ""){ $psi01 = 0; $psi02 = 9999999; } // Calculate the search range for GPM if ($gpm != ""){ $gpm1 = $gpm; $gpm2 = ($gpm * 1.2); } else if (!$gpm or $gpm == ""){ $gpm1 = 0; $gpm2 = 9999999; } // Send information and call the results result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results); } // If form has not been submitted else { ?> </strong> <form action="index.php?p=srchprod3" method="post"> <table width='405' height="285" border='0' cellpadding='3' cellspacing='0' style="background:url(<?=$siteadd?>/img/search-back.jpg); background-position:left; background-repeat:no-repeat; background-color:#000000"> <tr> <td width="512" height="22" style="background:url(<?=$siteadd?>/menus/images/newline.gif);"><strong><font color="#FFFFFF">Search</font></strong></td> </tr> <tr> <td height="260" align="left" valign="middle" ><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="37%" height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="psi" type="text" id="psi" style="width:120px;" onkeypress="return numeralsOnly(event)" value="<?=$psi?>" /> </strong></td> <td width="63%" height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Pressure per Square Inch <br /> <font size="1">(searches using max PSI) </font></font></strong></td> </tr> <tr> <td height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="gpm" type="text" id="gpm" style="width:120px;" onkeypress="return numeralsOnly(event)" value="<?=$gpm?>" /> </strong></td> <td height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Flow Rate<br /> <font size="1">(searches using max GPM) </font></font></strong></td> </tr> <tr> <td height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="model" type="text" id="mod" style="width:120px;" value="<?=$mod?>" /> </strong></td> <td height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Pump Model Number <br /> <font size="1">(i.e. KD-12 will display all pumps beginning with that) </font></font></strong></td> </tr> <tr> <td height="45" align="right" style="padding-right:10px;"><font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif"> <label> <font size="2">Continuous Duty<font color="#FFFFFF" face="Arial, Helvetica, sans-serif"> <input name="use01" type="radio" value="Continuous" <?php if ($use01 != "Intermittent") { echo "checked=checked";} ?> /> </font></font></label> <font size="2"> <br /> <label> Intermittent Duty<font color="#FFFFFF" face="Arial, Helvetica, sans-serif"> <input name="use01" type="radio" value="Intermittent" <?php if ($use01 == "Intermittent") { echo "checked=checked";} ?> /> </font></label> </font> </font></td> <td height="45"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Usage<br /> </font></strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><font size="1"><strong>(Continuous: more than 6 hrs/day to 14<br /> hrs/day. fully loaded ) <br /> </strong></font><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><font size="1"><strong>(Intermittent: less than 6 hrs/day, loaded no<br /> more than 15 min. every hr.)</strong></font></font></font></td> </tr> <tr> <td align="center"><strong> <input type="submit" name="go" value="Search" style="width:120px;" /> </strong></td> <td> </td> </tr> </table></td> </tr> </table> <strong><br /> </strong> </form> <strong> <?php } // Show results function result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results) { include('db.php'); if ($model != "") { // Query if Model has been searched for $query_mem_1 = "SELECT * FROM `$pump_database_table` WHERE ( (`psi1` > $psi01 AND `psi1` < $psi02) OR (`psi2` > $psi01 AND `psi2` < $psi02) OR (`psi3` > $psi01 AND `psi3` < $psi02) OR (`psi4` > $psi01 AND `psi4` < $psi02) OR (`psi5` > $psi01 AND `psi5` < $psi02) OR (`psi6` > $psi01 AND `psi6` < $psi02) OR (`psi7` > $psi01 AND `psi7` < $psi02)) AND ( (`maxflow` > $gpm1 AND `maxflow` < $gpm2) OR (`flow2` > $gpm1 AND `flow2` < $gpm2) OR (`flow3` > $gpm1 AND `flow3` < $gpm2) OR (`flow4` > $gpm1 AND `flow4` < $gpm2) OR (`flow5` > $gpm1 AND `flow5` < $gpm2) OR (`flow6` > $gpm1 AND `flow6` < $gpm2) OR (`flow7` > $gpm1 AND `flow7` < $gpm2)) AND (`use` = '$use01') AND `model` LIKE CONVERT ( _utf8 '%$mod%' USING latin1 ) COLLATE latin1_swedish_ci ORDER BY maxflow ASC"; } else if (!$mod or $mod == ""){ // Query if Model was not searched for $query_mem_1 = "SELECT * FROM `$pump_database_table` WHERE ( (`psi1` > $psi01 AND `psi1` < $psi02) OR (`psi2` > $psi01 AND `psi2` < $psi02) OR (`psi3` > $psi01 AND `psi3` < $psi02) OR (`psi4` > $psi01 AND `psi4` < $psi02) OR (`psi5` > $psi01 AND `psi5` < $psi02) OR (`psi6` > $psi01 AND `psi6` < $psi02) OR (`psi7` > $psi01 AND `psi7` < $psi02)) AND ( (`maxflow` > $gpm1 AND `maxflow` < $gpm2) OR (`flow2` > $gpm1 AND `flow2` < $gpm2) OR (`flow3` > $gpm1 AND `flow3` < $gpm2) OR (`flow4` > $gpm1 AND `flow4` < $gpm2) OR (`flow5` > $gpm1 AND `flow5` < $gpm2) OR (`flow6` > $gpm1 AND `flow6` < $gpm2) OR (`flow7` > $gpm1 AND `flow7` < $gpm2)) AND (`use` = '$use01') ORDER BY maxflow ASC"; } // Fetch a count of all results $mem_1 = mysql_query($query_mem_1, $connection) or die(mysql_error()); $numOfRows = mysql_num_rows($mem_1); // No results if ($numOfRows == 0){ ?> </strong> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td background="menus/images/newline.gif"><strong><font color="#FFFFFF">Results: No Matches</font></strong></td> </tr> <tr> <td height="70" align="left" valign="top" class="prod"><strong>We're sorry. There were no matches for the search criteria you specified. Please try again.</strong></td> </tr> </table> <strong><br /> <?php } else { // Determine the number of pages $num_pages = ceil($numOfRows / $max_results); // Determine the starting result to print $start_result = ($page * $max_results) - $max_results; // Append to our query with our result limit $query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results.""; // Query for our current page of results $mem_1_limit = mysql_query($query_mem_1_limit, $connection) or die(mysql_error()); $row_mem_1_limit = mysql_fetch_assoc($mem_1_limit); // Print The results $numOfPageRows = mysql_num_rows($mem_1_limit); for ($i = 0; $i < $numOfPageRows; $i++){ $id = mysql_result ($mem_1, $i, "id"); $model = mysql_result ($mem_1, $i, "model"); $img = mysql_result ($mem_1, $i, "img"); $type = mysql_result ($mem_1, $i, "type"); $psi1 = mysql_result ($mem_1, $i, "psi1"); $maxflow = mysql_result ($mem_1, $i, "maxflow"); $use = mysql_result ($mem_1, $i, "use"); $cylinder = mysql_result ($mem_1, $i, "cylinder"); // conver numbers to words / cylinders if ($cylinder == '1'){ $cylinder = "Simplex"; } if ($cylinder == '2'){ $cylinder = "Duplex"; } if ($cylinder == '3'){ $cylinder = "Triplex"; } if ($cylinder == '5'){ $cylinder = "Quintuplex"; } if ($cylinder == '6'){ $cylinder = "Sextuplex"; } ?> </strong> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td colspan="2" background="menus/images/newline.gif"><strong><font color="#FFFFFF"> <?=$model?> </font></strong></td> </tr> <tr> <td width="186" height="70" align="left" valign="top" class="prod"><strong> <?=$use?> Duty<br /> <?=$cylinder?> <?=$type?> Pump <br /> Max PSI: <?=$psi1?> PSI<br /> Max Flow Rate: <?=$maxflow?> GPM</strong></td> <td width="180" height="70" align="right" valign="bottom" class="prod"><strong><a href='index.php?p=pmp&pid=<?=$id?>' class="prod">See this pump</a><br /> <?php if ($img != "img/pp/") { ?> <a href='pd.php?pid=<?=$id?>' onclick="NewWindow(this.href,'pd','690','420','no','center');return false" onfocus="this.blur" class="prod">View dimensions</a><br /> <?php } ?> <a href='calc.php' onclick="NewWindow(this.href,'pd','690','450','yes','center');return false" onfocus="this.blur" class="prod">View Pump Calculations</a></strong></td> </tr> </table> <br /> <?php } // Start pagination ?> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td colspan="2" background="menus/images/newline.gif"> <?php // Loop to print a button for each page of results for($j = 1;$j <= $num_pages;$j++){ // Check if we are printing the current page // we won't make it an active button $disabled = ($j == $page) ? "DISABLED" : NULL; ?> <form action="index.php?p=srchprod" method="post"> <input type="hidden" name="psi" id="psi" value="<?=$psi?>" /> <input type="hidden" name="gpm" id="gpm" value="<?=$gpm?>" /> <input type="hidden" name="page" id="page" value="<?=$page?>" /> <input type="hidden" name="use01" id="use01" value="<?=$use01?>" /> <input type="hidden" name="mod" id="mod" value="<?=$mod?>" /> <input type="hidden" name="page" id="page" value="<?=$j?>" /> <input type="submit" name="go" id="go" value="<?=$j?>" <?=$disabled?> /> </form> </td> </tr> </table> <?php } } } ?> </td> </tr> </table></td> </tr></table></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84051 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 Okay, the problem is that the individual pages are are all showing the same results Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84061 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 Any thoughts about the latest problem? =-( Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84106 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 pa-pa-pa-please help? I'm already starting to develope a sta-sta-stutter because my happiness level has gone down =-( Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84172 Share on other sites More sharing options...
HeyRay2 Posted September 1, 2006 Share Posted September 1, 2006 You've modified the code that I posted.Please post the code [b]exactly[/b] as you are using it now, so I can see exactly where the issue lies.Right off the bat though, I can see that we need to globalize several variables for use in your [b]result()[/b] function. Add these lines to the top of the function:[code]<?php // Show results function result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results) { global $psi, $gpm; // ... REST OF THE FUNCTION // ... // ... }?>[/code]Thanks... ;) Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84185 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 I posted exactly what you had but then had to change it because of errors :) I will surely try this in just a minute though Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84191 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 Okay, I made the changes and the page IS limiting the results to 4 per page, keeping the searched for variables and keeping the amount of pages, but it's showing the same 4 results (out of 10 total) on every page. Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84196 Share on other sites More sharing options...
HeyRay2 Posted September 1, 2006 Share Posted September 1, 2006 I know that there were syntax errors in the code I posted ( Posted for example, not for direct consumption... ;) ).Please post [b]YOUR[/b] code, exactly as it is in [b]YOUR[/b] file, with [b]YOUR[/b] changes included.Also, add this... [code=php:0]// Echo the queryecho $query_mem_1_limit.'<br>';[/code]...after this code:[code=php:0]// Append to our query with our result limit$query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results."";[/code] ;) Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84199 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 Updated. You can see the full query at http://www.kerrpumps.com/index.php?p=srchprod3I do appriciate your help. Sorry I'm not more into it, I'm used to figuring out problems myself.The code: [code]<table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="240" align="left" valign="top"><img src="img/pd-search.jpg" width="230" height="160" style="padding-right:6px;" /><br /> <br /> <br /> <br /> <a href="<?=$siteadd?>"><img src="img/page-logo.jpg" width="230" height="108" border="0" /></a></td> <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td><strong> <?php if ($go){ // If form submitted // Check if a page value was passed // if not, set the default page (1) if( isset($_POST['page']) && !empty($_POST['page']) && ctype_digit($_POST['page']) ){ $page = $_POST['page']; } else { $page = 1; } // Set the maximum results per page $max_results = 4; // Calculate the search range for PSI if ($psi != ""){ if ($psi < 1400){ $psi01 = $psi; $psi02 = ($psi * 1.19); } else if ($psi >= 1400){ $psi01 = $psi; $psi02 = ($psi * 1.21); } } else if (!$psi or $psi == ""){ $psi01 = 0; $psi02 = 9999999; } // Calculate the search range for GPM if ($gpm != ""){ $gpm1 = $gpm; $gpm2 = ($gpm * 1.2); } else if (!$gpm or $gpm == ""){ $gpm1 = 0; $gpm2 = 9999999; } // Send information and call the results result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results); } // If form has not been submitted else { ?> </strong> <form action="index.php?p=srchprod3" method="post"> <table width='405' height="285" border='0' cellpadding='3' cellspacing='0' style="background:url(<?=$siteadd?>/img/search-back.jpg); background-position:left; background-repeat:no-repeat; background-color:#000000"> <tr> <td width="512" height="22" style="background:url(<?=$siteadd?>/menus/images/newline.gif);"><strong><font color="#FFFFFF">Search</font></strong></td> </tr> <tr> <td height="260" align="left" valign="middle" ><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="37%" height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="psi" type="text" id="psi" style="width:120px;" onkeypress="return numeralsOnly(event)" value="<?=$psi?>" /> </strong></td> <td width="63%" height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Pressure per Square Inch <br /> <font size="1">(searches using max PSI) </font></font></strong></td> </tr> <tr> <td height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="gpm" type="text" id="gpm" style="width:120px;" onkeypress="return numeralsOnly(event)" value="<?=$gpm?>" /> </strong></td> <td height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Flow Rate<br /> <font size="1">(searches using max GPM) </font></font></strong></td> </tr> <tr> <td height="45" align="center" style="border-bottom: 1px solid #c0c0c0;"><strong> <input name="model" type="text" id="mod" style="width:120px;" value="<?=$mod?>" /> </strong></td> <td height="45" style="border-bottom: 1px solid #c0c0c0;"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Pump Model Number <br /> <font size="1">(i.e. KD-12 will display all pumps beginning with that) </font></font></strong></td> </tr> <tr> <td height="45" align="right" style="padding-right:10px;"><font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif"> <label> <font size="2">Continuous Duty<font color="#FFFFFF" face="Arial, Helvetica, sans-serif"> <input name="use01" type="radio" value="Continuous" <?php if ($use01 != "Intermittent") { echo "checked=checked";} ?> /> </font></font></label> <font size="2"> <br /> <label> Intermittent Duty<font color="#FFFFFF" face="Arial, Helvetica, sans-serif"> <input name="use01" type="radio" value="Intermittent" <?php if ($use01 == "Intermittent") { echo "checked=checked";} ?> /> </font></label> </font> </font></td> <td height="45"><strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Usage<br /> </font></strong><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><font size="1"><strong>(Continuous: more than 6 hrs/day to 14<br /> hrs/day. fully loaded ) <br /> </strong></font><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"><font size="1"><strong>(Intermittent: less than 6 hrs/day, loaded no<br /> more than 15 min. every hr.)</strong></font></font></font></td> </tr> <tr> <td align="center"><strong> <input type="submit" name="go" value="Search" style="width:120px;" /> </strong></td> <td> </td> </tr> </table></td> </tr> </table> <strong><br /> </strong> </form> <strong> <?php } // Show results function result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results) { global $psi, $gpm; include('db.php'); if ($model != "") { // Query if Model has been searched for $query_mem_1 = "SELECT * FROM `$pump_database_table` WHERE ( (`psi1` > $psi01 AND `psi1` < $psi02) OR (`psi2` > $psi01 AND `psi2` < $psi02) OR (`psi3` > $psi01 AND `psi3` < $psi02) OR (`psi4` > $psi01 AND `psi4` < $psi02) OR (`psi5` > $psi01 AND `psi5` < $psi02) OR (`psi6` > $psi01 AND `psi6` < $psi02) OR (`psi7` > $psi01 AND `psi7` < $psi02)) AND ( (`maxflow` > $gpm1 AND `maxflow` < $gpm2) OR (`flow2` > $gpm1 AND `flow2` < $gpm2) OR (`flow3` > $gpm1 AND `flow3` < $gpm2) OR (`flow4` > $gpm1 AND `flow4` < $gpm2) OR (`flow5` > $gpm1 AND `flow5` < $gpm2) OR (`flow6` > $gpm1 AND `flow6` < $gpm2) OR (`flow7` > $gpm1 AND `flow7` < $gpm2)) AND (`use` = '$use01') AND `model` LIKE CONVERT ( _utf8 '%$mod%' USING latin1 ) COLLATE latin1_swedish_ci ORDER BY maxflow ASC"; } else if (!$mod or $mod == ""){ // Query if Model was not searched for $query_mem_1 = "SELECT * FROM `$pump_database_table` WHERE ( (`psi1` > $psi01 AND `psi1` < $psi02) OR (`psi2` > $psi01 AND `psi2` < $psi02) OR (`psi3` > $psi01 AND `psi3` < $psi02) OR (`psi4` > $psi01 AND `psi4` < $psi02) OR (`psi5` > $psi01 AND `psi5` < $psi02) OR (`psi6` > $psi01 AND `psi6` < $psi02) OR (`psi7` > $psi01 AND `psi7` < $psi02)) AND ( (`maxflow` > $gpm1 AND `maxflow` < $gpm2) OR (`flow2` > $gpm1 AND `flow2` < $gpm2) OR (`flow3` > $gpm1 AND `flow3` < $gpm2) OR (`flow4` > $gpm1 AND `flow4` < $gpm2) OR (`flow5` > $gpm1 AND `flow5` < $gpm2) OR (`flow6` > $gpm1 AND `flow6` < $gpm2) OR (`flow7` > $gpm1 AND `flow7` < $gpm2)) AND (`use` = '$use01') ORDER BY maxflow ASC"; } // Fetch a count of all results $mem_1 = mysql_query($query_mem_1, $connection) or die(mysql_error()); $numOfRows = mysql_num_rows($mem_1); // No results if ($numOfRows == 0){ ?> </strong> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td background="menus/images/newline.gif"><strong><font color="#FFFFFF">Results: No Matches</font></strong></td> </tr> <tr> <td height="70" align="left" valign="top" class="prod"><strong>We're sorry. There were no matches for the search criteria you specified. Please try again.</strong></td> </tr> </table> <strong><br /> <?php } else { // Determine the number of pages $num_pages = ceil($numOfRows / $max_results); // Determine the starting result to print $start_result = ($page * $max_results) - $max_results; // Append to our query with our result limit $query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results.""; // Display the query echo $query_mem_1_limit.'<br>'; // Query for our current page of results $mem_1_limit = mysql_query($query_mem_1_limit, $connection) or die(mysql_error()); $row_mem_1_limit = mysql_fetch_assoc($mem_1_limit); // Print The results $numOfPageRows = mysql_num_rows($mem_1_limit); for ($i = 0; $i < $numOfPageRows; $i++){ $id = mysql_result ($mem_1, $i, "id"); $model = mysql_result ($mem_1, $i, "model"); $img = mysql_result ($mem_1, $i, "img"); $type = mysql_result ($mem_1, $i, "type"); $psi1 = mysql_result ($mem_1, $i, "psi1"); $maxflow = mysql_result ($mem_1, $i, "maxflow"); $use = mysql_result ($mem_1, $i, "use"); $cylinder = mysql_result ($mem_1, $i, "cylinder"); // conver numbers to words / cylinders if ($cylinder == '1'){ $cylinder = "Simplex"; } if ($cylinder == '2'){ $cylinder = "Duplex"; } if ($cylinder == '3'){ $cylinder = "Triplex"; } if ($cylinder == '5'){ $cylinder = "Quintuplex"; } if ($cylinder == '6'){ $cylinder = "Sextuplex"; } ?> </strong> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td colspan="2" background="menus/images/newline.gif"><strong><font color="#FFFFFF"> <?=$model?> </font></strong></td> </tr> <tr> <td width="186" height="70" align="left" valign="top" class="prod"><strong> <?=$use?> Duty<br /> <?=$cylinder?> <?=$type?> Pump <br /> Max PSI: <?=$psi1?> PSI<br /> Max Flow Rate: <?=$maxflow?> GPM</strong></td> <td width="180" height="70" align="right" valign="bottom" class="prod"><strong><a href='index.php?p=pmp&pid=<?=$id?>' class="prod">See this pump</a><br /> <?php if ($img != "img/pp/") { ?> <a href='pd.php?pid=<?=$id?>' onclick="NewWindow(this.href,'pd','690','420','no','center');return false" onfocus="this.blur" class="prod">View dimensions</a><br /> <?php } ?> <a href='calc.php' onclick="NewWindow(this.href,'pd','690','450','yes','center');return false" onfocus="this.blur" class="prod">View Pump Calculations</a></strong></td> </tr> </table> <br /> <?php } // Start pagination ?> <table width='405' border='0' cellspacing='0' cellpadding='3' style='border: 0px solid White;'> <tr> <td colspan="2"> <?php // Loop to print a button for each page of results for($j = 1;$j <= $num_pages;$j++){ // Check if we are printing the current page // we won't make it an active button $disabled = ($j == $page) ? "DISABLED" : NULL; ?> <form action="index.php?p=srchprod3" method="post"> <input type="hidden" name="psi" id="psi" value="<?=$psi?>" /> <input type="hidden" name="gpm" id="gpm" value="<?=$gpm?>" /> <input type="hidden" name="page" id="page" value="<?=$page?>" /> <input type="hidden" name="use01" id="use01" value="<?=$use01?>" /> <input type="hidden" name="mod" id="mod" value="<?=$mod?>" /> <input type="hidden" name="page" id="page" value="<?=$j?>" /> <input type="submit" name="go" id="go" value="<?=$j?>" <?=$disabled?> /> </form>(((DEBUG)))<br /> PSI:<?=$psi?><br />GPM:<?=$gpm?><br />Page:<?=$page?><br />Use01:<?=$use01?><br />Mod:<?=$mod?><br />J:<?=$j?><br />Disabled:<?=$disabled?><br /><br /> </td> </tr> </table> <?php } } } ?> </td> </tr> </table></td> </tr></table></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84203 Share on other sites More sharing options...
HeyRay2 Posted September 1, 2006 Share Posted September 1, 2006 Geez! I totally missed this! :oYour code is not printing results from the right query (we're printing from the [b]$query_mem_1[/b] query, which was used to get the total amount of results, so we're always starting at result 0)! We should be using results from the the [b]$query_mem_1_limit[/b] query!Change this code:[code=php:0] // Determine the number of pages $num_pages = ceil($numOfRows / $max_results); // Determine the starting result to print $start_result = ($page * $max_results) - $max_results; // Append to our query with our result limit $query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results.""; // Display the query echo $query_mem_1_limit.'<br>'; // Query for our current page of results $mem_1_limit = mysql_query($query_mem_1_limit, $connection) or die(mysql_error()); $row_mem_1_limit = mysql_fetch_assoc($mem_1_limit); // Print The results $numOfPageRows = mysql_num_rows($mem_1_limit); for ($i = 0; $i < $numOfPageRows; $i++){ $id = mysql_result ($mem_1, $i, "id"); $model = mysql_result ($mem_1, $i, "model"); $img = mysql_result ($mem_1, $i, "img"); $type = mysql_result ($mem_1, $i, "type"); $psi1 = mysql_result ($mem_1, $i, "psi1"); $maxflow = mysql_result ($mem_1, $i, "maxflow"); $use = mysql_result ($mem_1, $i, "use"); $cylinder = mysql_result ($mem_1, $i, "cylinder");[/code]... to this ...[code=php:0] // Determine the number of pages $num_pages = ceil($numOfRows / $max_results); // Determine the starting result to print $start_result = ($page * $max_results) - $max_results; // Append to our query with our result limit $query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results.""; // Query for our current page of results $mem_1_limit = mysql_query($query_mem_1_limit, $connection) or die(mysql_error()); while( $row_mem_1_limit = mysql_fetch_assoc($mem_1_limit) ){ $id = $row_mem_1_limit['id']; $model = $row_mem_1_limit['model']; $img = $row_mem_1_limit['img']; $type = $row_mem_1_limit['type']; $psi1 = $row_mem_1_limit['psi1']; $maxflow = $row_mem_1_limit['maxflow']; $use = $row_mem_1_limit['use']; $cylinder = $row_mem_1_limit['cylinder'];[/code]That should fix things up for you! ;) Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84230 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 Holy crap dude. I think it worked. Go check it out. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84237 Share on other sites More sharing options...
HeyRay2 Posted September 1, 2006 Share Posted September 1, 2006 Looks like it's printing the correct results for each page! :)Some formatting changes to your pagination link layout and you'll be all set!Glad to help! ;) Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84242 Share on other sites More sharing options...
zero118 Posted September 1, 2006 Author Share Posted September 1, 2006 *will be sure to come back here the next time he has a seemingly simple problem that will turn into a 2 page discussion*:) Quote Link to comment https://forums.phpfreaks.com/topic/19196-pagination/#findComment-84245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.