Hi,
I'm really stuck now. I want to have a set amount of results on my page at a time (paginate) but I cant get the prev/next buttons to work to fetch the next 25 results. I'm using php4 and mysql. Here's the code I used:
<?php
// open the connection
$conn = mysql_connect("localhost", "", ""
;
// pick the database to use
mysql_select_db("db",$conn);
$limit = 25;
$query_count = "SELECT count(*) FROM users";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM users LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!"
;
}
print "<table border=1><tr><th>id</th>";
print "<th>name</th><th>desc</th><th>pics</th><th>pic1</th><th>pic2</th></tr>";
// go through each row in the result set and display data
while ($newArray = mysql_fetch_array($result)) {
// give a name to the fields
$id = $newArray['id'];
$name = $newArray['name'];
$desc = $newArray['desc'];
$pics = $newArray['pics'];
$pic1 = $newArray['pic1'];
$pic2 = $newArray['pic2'];
//echo the results on screen
echo "
<tr>
<td>$id</td>
<td>$name</td>
<td><img src=\"$pics"></td>
<td>$desc</td>
<td>$pic1</td>
<td>$pic2</td>
</tr>
";
}
print "</table>";
if($page != 1){
$pageprev = $page--;
echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "
;
}else{
echo("PREV".$limit." "
;
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." "
;
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "
;
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." "
;
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "
;
}
}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page++;
echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"
;
}else{
echo("NEXT".$limit);
}
mysql_free_result($result);
?>
Reality is built on a foundation of dreams.
I'm really stuck now. I want to have a set amount of results on my page at a time (paginate) but I cant get the prev/next buttons to work to fetch the next 25 results. I'm using php4 and mysql. Here's the code I used:
<?php
// open the connection
$conn = mysql_connect("localhost", "", ""

// pick the database to use
mysql_select_db("db",$conn);
$limit = 25;
$query_count = "SELECT count(*) FROM users";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM users LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!"

}
print "<table border=1><tr><th>id</th>";
print "<th>name</th><th>desc</th><th>pics</th><th>pic1</th><th>pic2</th></tr>";
// go through each row in the result set and display data
while ($newArray = mysql_fetch_array($result)) {
// give a name to the fields
$id = $newArray['id'];
$name = $newArray['name'];
$desc = $newArray['desc'];
$pics = $newArray['pics'];
$pic1 = $newArray['pic1'];
$pic2 = $newArray['pic2'];
//echo the results on screen
echo "
<tr>
<td>$id</td>
<td>$name</td>
<td><img src=\"$pics"></td>
<td>$desc</td>
<td>$pic1</td>
<td>$pic2</td>
</tr>
";
}
print "</table>";
if($page != 1){
$pageprev = $page--;
echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "

}else{
echo("PREV".$limit." "

}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." "

}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "

}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." "

}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "

}
}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page++;
echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"

}else{
echo("NEXT".$limit);
}
mysql_free_result($result);
?>
Reality is built on a foundation of dreams.