Jump to content

prev 1 2 3 4 5 next page?


Recommended Posts

<?php

my connections are here!

......

// create the SQL statement

$sql = "SELECT * FROM Manchester ORDER BY EstablishmentName ASC";

 

// execute the SQL statement

$result = mysql_query($sql, $conn) or die(mysql_error());

 

//go through each row in the result set and display data

while ($newArray = mysql_fetch_array($result)) {

// give a name to the fields

 

//echo the results onscreen

echo "<p><img src='http://www.mydomain.com/photos/$Hotel_Id/AAB$Hotel_Id.jpg' alt='$EstablishmentName' width='100' height='75'><br>

<a href='$Homehyperlink'>$EstablishmentName</a><br>

$Address1 $Address2 $Town $Postcode<br><br>

$Description<br>

Prices from £$Rooms_From.

</p>";

}

 

// If current page number, use it

// if not, set one!

if(!isset($_GET['testall'])){

$page = 1;

} else {

$page = $_GET['testall'];

}

 

// Define the number of results per page

$max_results = 8;

 

// 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 = mysql_query("SELECT * FROM Manchester LIMIT $from, $max_results");

 

while($row = mysql_fetch_array($sql)){

// Build your formatted results here.

echo $row['title']."<br />";

$Hotel_Id = $newArray['Hotel_Id'];

$Homehyperlink = $newArray['HomeHyperlink'];

$Address1 = $newArray['Address1'];

$Address2 = $newArray['Address2'];

$Postcode = $newArray['PostCode'];

$Town = $newArray['Town'];

$County = $newArray['County'];

$Description = $newArray['Description'];

$EstablishmentName = $newArray['EstablishmentName'];

$Rooms_From = $newArray['Rooms_From'];

}

 

// Figure out the total number of results in DB:

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM Manchester"),0);

 

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

}

echo "</center>";

 

?>

 

please can anyone help fix the problems in this code so that i get a list of 8 hotels then it goes on to the next page and so on. at the moment it creating a page with all the hotels on it, and the prev, next, are at the bottom of the page, but they are not working

 

please help me!!!!

if you do not understand anything leave a reply and i will try to explain it a bit more!

Thank you very mch

lee

Link to comment
https://forums.phpfreaks.com/topic/1854-prev-1-2-3-4-5-next-page/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.