Jump to content


Photo

prev 1 2 3 4 5 next page?


  • Please log in to reply
No replies to this topic

#1 phplee

phplee
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 27 May 2004 - 11:59 AM

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

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

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users