Jump to content


Photo

Pagination Issue


  • Please log in to reply
2 replies to this topic

#1 ramtx

ramtx
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 10 February 2006 - 05:56 AM

I've got a bunch of results of a query from an HTML form on a page (searchform.php). The form action = results.php. It runs fine, but when I click on one of the pagination links the variables don't pass. Consequently, I get an error in my SQL because my query ends up being "....WHERE prop_beds = ''..."

I guess I need help passing the variables to my next page. Here's my code for results.php:


<?php
include 'dbconn.php';

//if current page number, use it
//if not, set one!
if(!isset($_GET['page'])){
  $page = 1;
} else {
  $page = $_GET['page'];
}

//define the number of results per page
$max_results = 15;

//figure out the limit for the query based
//on the current page number.
$from = (($page * $max_results) - $max_results);

//perform MySQL query on only the current page number's results
$sql = "SELECT * 
    FROM properties 
    WHERE prop_beds = '$beds'
    AND prop_price <= '$price'
    AND ("; 

    // loop through array of types:
        foreach($type_check as $value){
        $sql .= "prop_type = '$value' || ";
    }
        // remove last set of tubes and add closing parenthesis:
        $sql = substr($sql, 0, strlen($sql)-4) . ')' . "LIMIT $from, $max_results";     
        echo $sql;
      $query = mysql_query($sql) or die("Error: " . mysql_error());
    
//display headers
  echo '<table class="results" width="380" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td height="14"><b>PROP #</b></td>
    <td height="14"><b>BEDS</b></td>
    <td height="14"><b>BATHS</b></td>
    <td height="14"><b>PRICE</b></td>
    <td height="14"><b>TYPE</b></td>
    <td height="14"><b>LINK</b></td>
  </tr>';

while($row = mysql_fetch_array($query)) {
  //build your formatted results here.


  echo '<tr>
        <td height="14">WC-'.$row["prop_id"].'</td>
        <td height="14">'.$row["prop_beds"].'</td>
        <td height="14">'.$row["prop_baths"].'</td>
        <td height="14">$'.$row["prop_price"].'</td>
        <td height="14">'.$row["prop_type"].'</td>';
         
  if ($row["prop_url"]){    //start of link check
  echo'<td height="14"><a href ="javascript:newWindow(\''.$row["prop_url"].'\')"> PIX </a></td>';
  }
  else
  {                      //display X if no link exists
  echo '<td height="14"><b>X</b></td>
  </tr>';
  }                      //end of link check
}                      
  echo '</table>';
  echo '<div align = "center"> <span class="regText">';

//figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) FROM properties"),0);

echo $total_results;

//figure out the total number of pages always round up using ceil
$total_pages = ceil($total_results / $max_results);

//build page number hyperlinks
echo "<center>Select a Page<br />";

//build previous link
if($page > 1){
  $prev = ($page - 1);
  echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">Previous</a> "; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo $i." "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
    } 
} 

// Build Next Link 
if($page < $total_pages) { 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next</a>";

}else {
echo '<div align="center" class="regText">Sorry, no records match your criteria.</div></center>';
     }                
     //print message if no matching records
             //end of main
?>



Thanks in adavance.

#2 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 04 April 2006 - 08:02 PM

Did you ever get this fixed? I'm having the same problem right now and trying to work it out.

Brian's Web Design - Temecula

Freedom is only available through death.

#3 DrDre

DrDre
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 04 April 2006 - 09:12 PM

How are you initiating what results to show? Im seeing $blah and $blah and no specific method, so Im taking it your replying on superglobals, and using GET?

try search.php?beds={$beds}&price=$price}&othervars&page=<pagetogoto> for each of your pagination links.
[a href="http://forums.fanetworks.net" target="_blank"][/a]
» faNetworks Webmaster. [[a href="http://fanetworks.net" target="_blank"]fanetworks.net[/a]]
» faSoftware Developer [[a href="http://software.fanetworks.net" target="_blank"]software.fanetworks.net[/a]]
» faForums - php Resource + more [[a href="http://forums.fanetworks.net" target="_blank"]forums.fanetworks.net[/a]]
» Experienced php Coder - Ill help anyone I can if I have time ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users