Jump to content


Photo

"Pagination"


  • Please log in to reply
20 replies to this topic

#1 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 30 August 2006 - 07:12 PM

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.

<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 submitted
if (!$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">&nbsp;&nbsp;&nbsp;<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>
                          &nbsp;&nbsp;&nbsp;</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>&nbsp;</td>
                      </tr>
                    </table></td>
                </tr>
              </table>
              <strong><br />
              </strong>
            </form>
            <strong>
            <?php	}
	

// Show results
function 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 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 }

// 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 / 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 			}
						}
					}  ?>

            </td>
        </tr>
      </table></td>
  </tr>
</table>
</body></html>


#2 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 30 August 2006 - 07:43 PM

add
if (isset($_POST)) foreach ($_POST as $k => $v) $$k = $v;
after 1st '<?php' (line 12)

#3 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 30 August 2006 - 07:48 PM

Umm, thanks for the reply but I don't think that has anything to do with my issue...

#4 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 30 August 2006 - 10:45 PM

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 $page variable
and set a variable to limit results per page ($max_results):

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

	   ?>

I changed your result() function to include the current page and the maximum results per page variables
in it's argument list. This will allow that function to do you pagination.

You'll also notice I changed this:


// If form has not been submitted
if (!$go == '' or !$go) { ?>


to this:

// If form has not been submitted
else {

Since you've already checked if $go was true, there's no need to check any other condition,
because if $go is not TRUE, then it has to be FALSE.

Next, I'll go over changes within your result() function:

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

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 by
dividing the total result rows and diving by the results per page. I use the ceil() function to round up
if 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

// 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);

After printing the results, we print a small form for each page button. This will ensure that your search values get passed
to each result page, so your query will pull the right values. Each button is named go, so that your code you had
to check if the form was submitted will be executed for each page link.


The full modified code is below:


<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">&nbsp;&nbsp;&nbsp;<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>
                          &nbsp;&nbsp;&nbsp;</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>&nbsp;</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>


Good luck... ;)

#5 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 31 August 2006 - 02:19 PM

Thanks for your help.  I have a feeling this will work if I can just get past the syntax errors :)  http://www.kerrpumps...php?p=srchprod3

This shows an error on line 18 that I can't figure out.
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

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

#6 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 31 August 2006 - 02:51 PM

Anyone have some thoughts? :)

#7 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 31 August 2006 - 03:49 PM

ANY ideas are welcome :P

#8 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 31 August 2006 - 03:51 PM

must be
if( isset($_POST['page']) && !empty($_POST['page']) && ctype_digit($_POST['page']) ){


#9 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 September 2006 - 02:48 PM

Thanks guys!  Almost there!!!
http://www.kerrpumps...php?p=srchprod3

Check out the search results.  (search for a psi of 1300 to get a good amount).
Max_Results = 4 (to test the pagination)

<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">&nbsp;&nbsp;&nbsp;<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>
                          &nbsp;&nbsp;&nbsp;</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>&nbsp;</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>


#10 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 September 2006 - 02:57 PM

Okay, the problem is that the individual pages are are all showing the same results

#11 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 September 2006 - 04:20 PM

Any thoughts about the latest problem? =-(

#12 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 September 2006 - 06:09 PM

pa-pa-pa-please help?  I'm already starting to develope a sta-sta-stutter because my happiness level has gone down =-(

#13 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 01 September 2006 - 06:29 PM

You've modified the code that I posted.

Please post the code exactly 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 result() function. Add these lines to the top of the function:

<?php

		// Show results
		function result($psi01, $psi02, $gpm1, $gpm2, $use01, $mod, $page, $max_results)
		{
			
			global $psi, $gpm;
		
			// ... REST OF THE FUNCTION
			// ...
			// ...
			
		}

?>


Thanks... ;)

#14 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 September 2006 - 06:39 PM

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

#15 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 September 2006 - 06:47 PM

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.

#16 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 01 September 2006 - 06:52 PM

I know that there were syntax errors in the code I posted ( Posted for example, not for direct consumption... ;) ).

Please post YOUR code, exactly as it is in YOUR file, with YOUR changes included.

Also, add this...

// Echo the query
echo $query_mem_1_limit.'<br>';

...after this code:

// Append to our query with our result limit
$query_mem_1_limit = $query_mem_1 . " LIMIT ".$start_result.",".$max_results."";

;)

#17 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 September 2006 - 07:08 PM

Updated.  You can see the full query at http://www.kerrpumps...php?p=srchprod3

I do appriciate your help.  Sorry I'm not more into it, I'm used to figuring out problems myself.

The 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">&nbsp;&nbsp;&nbsp;<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>
                          &nbsp;&nbsp;&nbsp;</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>&nbsp;</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>


#18 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 01 September 2006 - 08:11 PM

Geez! I totally missed this!  :o

Your code is not printing results from the right query (we're printing from the $query_mem_1 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 $query_mem_1_limit query!

Change this code:

				// 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");


... to this ...


				// 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'];

That should fix things up for you!

;)

#19 zero118

zero118
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 September 2006 - 08:21 PM

Holy crap dude.  I think it worked.  Go check it out.  Thank you very much.

#20 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 01 September 2006 - 08:24 PM

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!  ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users