Hi!
I went through this URL: http://www.phpfreaks.com/tutorials/43/3.php, and i understood it. Thanks "bailo81", but i have an issue here.
Even though the code basically works, the hyperlink to other pages doesn't work, it doesn't get highlighted. I have tested it with a small table having 25 rows.
Since i am new to php, i cannot figure out what's wrong. I'll post the code and the outcome.
Please help me.
Thanks & regards,
Pradee.
Outcome looks like below:
Id Rate
1 8
2 7
3 8
4 8
5 3
PREV5 1 NEXT5
Code:
<?php
$localhost = '192.168.101.7';
$user = 'root';
$password = '';
$database = 'forcestravel';
@mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER");
@mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");
$limit = 5;
$query_count = "SELECT count(*) FROM discount";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM discount LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}
$bgcolor = "#E0E0E0"; // light gray
echo("<table>");
echo("<tr>");
echo("<td>Id</td>");
echo("<td>Rate</td>");
echo("</tr>");
while($row = mysql_fetch_array($result)){
if ($bgcolor == "#E0E0E0"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0E0E0";
}
echo("<tr bgcolor=".$bgcolor."><td>");
echo($row["id"]);
echo("</td><td>");
echo($row["rate"]);
echo("</td></tr>");
}
echo("</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);
?>