PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
that is not the problem it doesn't get a true on the if condition. any way i got my hands on the pagination code from http://www.phpeasystep.com/phptu/29.html and it worked fin when i tested it but when i tried to apply it on my site it didn't work
<?php
/*
Place code to connect to your DB here.
*/
include('connection.php'); // include your code to connect to DB.
$tbl_name="mawdoatseyaseya"; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = 3;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
/* Setup vars for query. */
$targetpage = "index.php?page=mawdoatseyaseya&"; //your file name (the name of this file)
$limit = 15; //how many items to show per page
$page_num = $_GET['page_num'];
if($page_num)
$start = ($page_num - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
/* Get data. */
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);
/* Setup page vars for display. */
if ($page_num == 0) $page_num = 1; //if no page var is given, default to 1.
$prev = $page_num - 1; //previous page is page - 1
$next = $page_num + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page_num > 1)
$pagination.= "<a href=\"$targetpage?page_num=$prev\">« السابق</a>";
else
$pagination.= "<span class=\"disabled\">« السابق</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page_num)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page_num=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page_num < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page_num)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page_num=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page_num=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page_num=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page_num && $page_num > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page_num=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page_num=2\">2</a>";
$pagination.= "...";
for ($counter = $page_num - $adjacents; $counter <= $page_num + $adjacents; $counter++)
{
if ($counter == $page_num)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page_num=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page_num=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page_num=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page_num=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page_num=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page_num)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page_num=$counter\">$counter</a>";
}
}
}
//next button
if ($page_num < $counter - 1)
$pagination.= "<a href=\"$targetpage?page_num=$next\">التالي »</a>";
else
$pagination.= "<span class=\"disabled\">التالي »</span>";
$pagination.= "</div>\n";
}
?>
<?php
echo '<br><table class="sample" style="width:95%;"><tbody><tr><th style="width:70%;">العنوان</th><th style="width:20%;">التاريخ</th></tr>';
while($row = mysql_fetch_array($result))
{
echo '<tr><td>';
echo '<a href="'.$row["mawdoatseyaseya"].'"style="font-size:130%;color:blue">'.$row["mawdoatseyaseya_title"].'  (<label style="font-size:10px;">'.(round(filesize($row["mawdoatseyaseya"])/(1024*1024),2)).'م.ب</label>)</a>';
echo '</td><td>';
echo date("d-m-Y",$row[date]);
echo '</td></tr>';
}
echo '</tbody></table><br><span class="center2">';
echo $pagination;
echo '</span>';
?>
<?php=$pagination?>
only the first page shows up, when i try to go to the next page it changes the page_num from 1 to 2 but the displayed data is the same from the page_num=1
i think the problem is here