Paginating Puzzle - code not working on life server
Posted: Sat Jan 29, 2011 7:45 am
I am geting some output of a db table to be viewed on a admin page. Since there are more than 400 entries in the db the viewing page need paginating. The following code works fine on my test environment, WAMP server on windows xp pro. Soon as the hole thing goes on the live linux server only the first 20 entries are showing and the links for the following pages don't even show.
The viewing page is called through a index page lying in the admin folder. There are to functions included coming from two differnet classes in a system folder.
database connection and includes are all done on the admin index page.
The following code is used to get the db data to be displayed:
Here is the function out of the class page where we get the table entries from:
Finally the portion of the mysql class counting the table entries:
As I said, the code works fine in my test environment showing the links to the required pages as
1 | 2 | 3 | .....
Not very nice in design but its only backend to be viewed by me.
If anybody got an idea why it is working on localhost and not on a live linux server, I would be glad to hear.
Thanks a lot
The viewing page is called through a index page lying in the admin folder. There are to functions included coming from two differnet classes in a system folder.
database connection and includes are all done on the admin index page.
The following code is used to get the db data to be displayed:
Code: Select all
<h1>Pages</h1>
<p>
<a href="/admin/index.php?page=site-new">New Page</a>
</p>
<?php
//print_r(page::getpages())
?>
<table>
<thead>
<tr>
<td><strong>Title</strong></td>
<td><strong>Alias</strong></td>
<td><strong>Actions</strong></td>
</tr>
</thead>
<tbody>
<?php
foreach(page::getpages(@$_GET['sitepage'] * 20,20) as $entry) //here we get the portion of entries we need to display
{
echo "<tr>
<td>".$entry['title']."</td>
<td>".$entry['alias']."</td>
<td><a title=\"Edit with WYSIWYG\"
href=\"index.php?page=site-edit&site=".$entry['alias']."\">
<img src=\"../system/images/icons/page_edit.png\" /></a>
<a title=\"Edit with plain text editor\"
href=\"index.php?page=site-edit-st&site=".$entry['alias']."\">
<img src=\"../system/images/icons/building_edit.png\" /></a>
<a title=\"Delete\"
href=\"index.php?page=site-delete&site=".$entry['alias']."\">
<img src=\"../system/images/icons/cross.png\" /></a></td>
</tr>";
}
?>
</tbody>
</table>
<?php
$pagecount = ceil(MySQL::countTableEntries($dbpraefix."pages") / 20); //here we get the amount of pages needed to display 20 db entries on each page
for ($cPage = 0; $cPage < $pagecount; $cPage++)
{
echo "<a href=\"/admin/index.php?page=sites&sitepage=".$cPage."\"> ".($cPage + 1)." |</a>"; //this displays the links to the amount of avilable pages
}
?>
Code: Select all
function getpages($from, $count)
{
global $dbpraefix;
$res = mysql_query("SELECT * FROM ".$dbpraefix."pages
ORDER BY title LIMIT ".$from.", 20");
while($row = mysql_fetch_array($res))
{
$entries[] = $row;
}
return $entries;
}
Code: Select all
function countTableEntries($table)
{
$res = mysql_query("SELECT COUNT(*) FROM
".mysql_real_escape_string($table));
$row = mysql_fetch_row($res);
return $row[0];
}
1 | 2 | 3 | .....
Not very nice in design but its only backend to be viewed by me.
If anybody got an idea why it is working on localhost and not on a live linux server, I would be glad to hear.
Thanks a lot