Have an account? Sign in
Login  Register  Facebook
Problems with pagination
	  $name=$_GET['name'];
	  $country=$_GET['Country'];
	  $type=$_GET['Type'];
	  $L1=$_GET['L1'];
	  $L2=$_GET['L2'];
	  
    require_once ('pagination.php');	  
    	  echo $country;
    $conn = mysql_connect("localhost","root","");
    if (!$conn)
        {
        die('Could not connect: ' . mysql_error());
        }

    mysql_select_db("grech", $conn);
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Search Boats</title>

<!-- css skin -->
<link rel="stylesheet" type="text/css" href="style2.css" />
<style type="text/css">
a {
color:#333;
text-transform: capitalize;
}
a:hover{
color: #999;
text-decoration:underline
}
</style>
</head>
<body>
<?php

    $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
    $page = ($page == 0 ? 1 : $page);
    $perpage = 2;//limit in each page
    $startpoint = ($page * $perpage) - $perpage;

	
	//$g="select * FROM boats WHERE Country=$country LIMIT $startpoint,$perpage";

	$sql = "select * FROM boats WHERE
                     Country=$country AND
                     length BETWEEN $L1 AND $L2
                         LIMIT $startpoint,$perpage;";
	$result =mysql_query($sql);
	//$result=mysql_query($sql); 


echo "<table width = '60%' border='0' cellspacing = '0' >
        <tr>
            <th>Model</th>
            <th>Length</th>
            <th>Engine</th>
            <th>Powerplant</th>
            <th>Price</th>
            <th>Country</th>
        </tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Model'] . "</td>";
  echo "<td>" . $row['length'] . "</td>";
  echo "<td>" . $row['engine'] . "</td>";
  echo "<td>" . $row['powerplant'] . "</td>";
  echo "<td>" . $row['price'] . "</td>";
  echo "<td>" . $row['Country'] . "</td>";
   
  
  $joe = $row['BoatId'];
  echo "<td>
            <form  method='post' action='details.php?go'  id='searchform2'>
                <input type='hidden' name='hideID' value = '$joe'/>
                <input type='submit' name='submit' value='more info'/>
            </form></td>";
  echo "</tr>";
  
  echo "<tr>";
  echo "<td colspan = '7'> " . '<hr />' . "</td>";
  echo "</tr>";
	
	}
echo "</table>";
//show pages
	echo Pages("boats WHERE Country=$country
                         AND length BETWEEN $L1 AND $L2", $perpage, "search4.php?");
	
	mysql_close($conn);
	
////
?>
</body>
</html>


i'm doing this Boat database with pagination using a tutorial from this site. Only the first page shows. I don't seem to be able to send the variables to the next pages. What am I doing wrong pls?

Thanks a lot for any replies!!! :-)
Started: September 21, 2011 Latest Activity: September 21, 2011 pagination

every thing seem ok!! are you sure from the mysql enrties?
September 21, 2011

is the entries are more than the perpage limit i mean more than 2?
September 21, 2011

do you mean the pages is working but the pages entries not working?
September 21, 2011

the results from the database are coming on the first page only. The rest of the pages give me errors. The problem is that the variables are not passing to the other pages...
September 21, 2011

@AntoineGre look at my answer.
September 21, 2011

1 Answer
hello @AntoineGre
because of your query depend on the $_GET you must make this in the new url some think like that:
$p_query = \"boats WHERE Country=$country AND length BETWEEN $L1 AND $L2\"; 
$p_url = \"search4.php?name=$name&Country=$country&Type=$type&L1=$L1&L2=$L2&\";

    echo Pages($p_query,$perpage,$p_url);

this will make the pages url :search4.php?name=&Country=&Type=&L1=&L2=&page=

Posted: MacOS
In: September 21, 2011

Thanks so so much!!!!! This will help me for sure! Just one question: How can I make my url look like this? Search4.Php?Page=2Name=
September 21, 2011

thanks so so much!!!!!!
September 21, 2011

the function will not accept that 'Search4.Php?Page=2Name=' i will take a look and try to update it
September 21, 2011

function Pages($tbl_name,$limit,$path) { $query = "SELECT COUNT(*) as num FROM boats WHERE Country=$country AND length BETWEEN $L1 AND $L2;";
September 21, 2011

hi, it works perfectly now!!!!! THANKS just one last question!!!! what is wrong with the above statement??? cause when i give it parameters (WHERE Country....) it gives me an error
September 21, 2011

try use my method "SELECT COUNT(*) as num FROM $tbl_name"
September 21, 2011

That was awesome!! brilliant!!! worked really fine, thanks so so much!!! :-)
September 21, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer