LuckySyringe
Technical User
I need to limit my rows as well as print out the data inversely, so the most recent additions come out on top and there is only six results on one page. This is what I have so far:
Code:
<?php
$start = $_GET['start'];
$offset = $_GET['offset'];
if (!$start || !$offset) {
$start = 0;
$offset = 6;}
$end = $start + $offset;
$dbHost = 'localhost';
$dbUser = 'tempuser';
$dbPass = 'temppass';
$dbDatabase = 'tempdatabase';
$dbTable = 'temptable';
$dbConnection = @mysql_connect($dbHost, $dbUser, $dbPass) or die("Could not connect: ".mysql_error()."<br />");
@mysql_select_db("$dbDatabase") or die("Could not select database.<br />");
// I want this so that the start number and the offset are in the url
// and a link under the printed results with new start and offset numbers
$query = "SELECT * FROM ".$dbTable." LIMIT ".$start.",".$offset;
$result = @mysql_query($query) or die ('Query failed: '.mysql_error().'<br />');
$num_results = @mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++) {
$row = @mysql_fetch_assoc($result);
echo "\t<p class=\"item\">\n".
"\t\t<a href=\"".$dbTable."/item.php?id=".stripslashes($row['id'])."\">".stripslashes($row['id'])."</a>\n".
"\t\t<span class=\"item-title\"><a href=\"".$dbTable."/item.php?id=".stripslashes($row['id'])."\">".htmlspecialchars(stripslashes($row['title']))."</a></span>".
"\t\t<span class=\"item-info\">".stripslashes($row['description'])."</span>".
"\t</p>\n";}
/*
$start = $i + 1;
echo "<p>".$i." - ".$end." of ".$num_results." "; // I realize this is redundant
// This is where the previous / next page will be printed
switch ($i) {
case $i < 8;
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=list&start=".$start."&offset=".$offset."\">Next Page</a>";
break;
case $i > 8;
$prev = $start - $offset;
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=list&start=".$prev."&offset=".$offset."\">Previous Page</a> <a href=\"".$_SERVER['PHP_SELF']."?page=list&start=".$start."&offset=".$offset."\">Next Page</a>";
break;
}
echo "</p>";
*/
@mysql_free_result($result);
@mysql_close($dbConnection);
?>