Paginating Puzzle - code not working on life server

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!

Moderator: General Moderators

Post Reply
divedj
Forum Commoner
Posts: 47
Joined: Wed Dec 29, 2010 4:32 am
Location: Malta

Paginating Puzzle - code not working on life server

Post by divedj »

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:

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
   }
 ?>
Here is the function out of the class page where we get the table entries from:

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;
    }
Finally the portion of the mysql class counting the table 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];
       }

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
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: Paginating Puzzle - code not working on life server

Post by Peter Kelly »

I havent looked through your code as of yet but are you connecting to the same db? and does the database have all the rows in it on the live server?
divedj
Forum Commoner
Posts: 47
Joined: Wed Dec 29, 2010 4:32 am
Location: Malta

Re: Paginating Puzzle - code not working on life server

Post by divedj »

I just rechecked the lines in the db. There are all the same and since it is one dbconnect file beeing included and the rest is all working fine, I am connecting to the correct db.
The frontend pages are called with index.php?page= and modified with mode rewrite in htaccess. The information which page is loaded is coming from the same db table and that is all working fine also on the live server.
I am more thinking of something like linux is very fuzzy about what if run on a windows plathform is tolerated like uppercase letters in file names for example. However there still might be something else I just missed...

Thanks for any help on this.
Post Reply