Jump to content

"Pagination"


zero118

Recommended Posts

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 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>[/code]
Link to comment
Share on other sites

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] variable
and 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 variables
in 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 submitted
if (!$go == '' or !$go) { ?>

[/code]

to this:

[code=php:0]
// If form has not been submitted
else {
[/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 by
dividing the total result rows and diving by the results per page. I use the [b]ceil()[/b] 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

[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 passed
to each result page, so your query will pull the right values. Each button is named [b]go[/b], 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:


[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">&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>
[/code]


Good luck... ;)
Link to comment
Share on other sites

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=srchprod3

This 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!!
Link to comment
Share on other sites

Thanks guys!  Almost there!!!
http://www.kerrpumps.com/index.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)

[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)
{


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]
Link to comment
Share on other sites

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... ;)
Link to comment
Share on other sites

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 query
echo $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]

;)
Link to comment
Share on other sites

Updated.  You can see the full query at http://www.kerrpumps.com/index.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: [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>
[/code]
Link to comment
Share on other sites

Geez! I totally missed this!  :o

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

;)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.