Database pagination redirect issue

A multipurpose module, plugin and component

Database pagination redirect issue

New postby [email protected] » Wed Dec 08, 2010 4:47 pm

Dear All,
After much soul searching and banging of head I have finally relented and wish to seek help with my issue.

I have created a Jumi application to display the records of a database table, limiting the number of records to 10 and displaying the appropriate pagination. This has been tested to a point and works. The problem is when I use the pagination links - whenever I click a link (it doesn't matter which one) The next 10 records in the set are displayed however, they are displayed in a completely blank, and different page - effectively redirected away from the index.php page and the main content area.

I am a novice trying to learn so I don't really have the skills or knowledge to work out why this is happening. The only thing I can come up with is that it has something to do with the parameter getting passed, but to the wrong page if that makes sense.

The Jumi application has no custom script but rather links to a php file - components/com_jumi/files/annapage.php. I don't know why or how I come this conclusion but I feel the problem lies with this part of the code:

Code: Select all
$targetpage = "annapage.php";


Would someone be willing to take a look at this for me and point me in the right direction.

TIA & Regards

Chris Blair

you can see the contents of the annapage.php file here...

Code: Select all
<?php
   /*
      Place code to connect to your DB here.
   */
   // Connect to the database
   $dbLink = new mysqli('localhost', 'root', 'root', 'odt_db');
   if(mysqli_connect_errno()) {
       die("MySQL connection failed: ". mysqli_connect_error());
   }    

   $tbl_name="Annaveigh";      //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 = "annapage.php";    //your file name
   $limit = 10;                         //how many items to show per page
   $page = $_GET['page'];
   if($page)
      $start = ($page - 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 id, filename, custname, deldate, delnoteno, delrefno FROM $tbl_name ORDER BY delnoteno DESC LIMIT $start, $limit";
$result = $dbLink->query($sql);

// Check if it was successfull
if($result) {
    // Make sure there are some files in there
    if($result->num_rows == 0) {
        echo '<p>There are no files in the database</p>';
    }
    else {
        // Print the top of a table
        echo '<h1 class="epod">Annaveigh - EPOD - Retrieval System</h1>';
        echo '<table>
                <tr>
                    <td style="font-size:1.6em; color:#006;"><b>Customer Name</b></td>
                    <td style="font-size:1.6em; color:#006;"><b>Delivery Date</b></td>
                    <td style="font-size:1.6em; color:#006;"><b>Delivery Note No</b></td>
                    <td style="font-size:1.6em; color:#006;"><b>Delivery Ref No</b></td>
                    <td style="font-size:1.6em; color:#006;"><b>Filename</b></td>
                </tr>';     
    }
}
else
{
    echo 'Error! SQL query failed:';
    echo "<pre>{$dbLink->error}</pre>";
}

   
   /* Setup page vars for display. */
   if ($page == 0) $page = 1;               //if no page var is given, default to 1.
   $prev = $page - 1;                     //previous page is page - 1
   $next = $page + 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 > 1)
         $pagination.= "<a href=\"$targetpage?page=$prev\">« previous</a>";
      else
         $pagination.= "<span class=\"disabled\">« previous</span>";   
      
      //pages   
      if ($lastpage < 7 + ($adjacents * 2))   //not enough pages to bother breaking it up
      {   
         for ($counter = 1; $counter <= $lastpage; $counter++)
         {
            if ($counter == $page)
               $pagination.= "<span class=\"current\">$counter</span>";
            else
               $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";               
         }
      }
      elseif($lastpage > 5 + ($adjacents * 2))   //enough pages to hide some
      {
         //close to beginning; only hide later pages
         if($page < 1 + ($adjacents * 2))      
         {
            for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
            {
               if ($counter == $page)
                  $pagination.= "<span class=\"current\">$counter</span>";
               else
                  $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";               
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
            $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";      
         }
         //in middle; hide some front and some back
         elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
         {
            $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
            $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
            $pagination.= "...";
            for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
            {
               if ($counter == $page)
                  $pagination.= "<span class=\"current\">$counter</span>";
               else
                  $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";               
            }
            $pagination.= "...";
            $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
            $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";      
         }
         //close to end; only hide early pages
         else
         {
            $pagination.= "<a href=\"$targetpage?page=1\">1</a>";
            $pagination.= "<a href=\"$targetpage?page=2\">2</a>";
            $pagination.= "...";
            for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
            {
               if ($counter == $page)
                  $pagination.= "<span class=\"current\">$counter</span>";
               else
                  $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";               
            }
         }
      }
      
      //next button
      if ($page < $counter - 1)
         $pagination.= "<a href=\"$targetpage?page=$next\">next »</a>";
      else
         $pagination.= "<span class=\"disabled\">next »</span>";
      $pagination.= "</div>\n";      
   }
?>

   <?php
      // Your while loop here
              // Print each file
        while($row = $result->fetch_assoc()) {
            echo "
                <tr>
                    <td>{$row['custname']}</td>
                    <td>{$row['deldate']}</td>
                    <td>{$row['delnoteno']}</td>
                    <td>{$row['delrefno']}</td>      
               <td>{$row['filename']}</td>
                    <td><a href='components/com_jumi/files/get_file.php?id={$row['id']}'>Download</a></td>
                </tr>";
        }
// Close table
echo '</table>';
   ?>

<?=$pagination?>
[email protected]
 
Posts: 2
Joined: Wed Dec 08, 2010 4:31 pm

Re: Database pagination redirect issue

New postby [email protected] » Sun Dec 12, 2010 5:30 pm

Dear All,
I am really struggling with getting this to work for me. I am sure it is something quite simple but I don't have the knowledge to figure it out. Is there anyone who will take a look at this issue for me and point me in the right direction. The whole thing works just fine other than the pagination issue.

I would be most grateful for any help / support.

Best Regards

Chris Blair
[email protected]
 
Posts: 2
Joined: Wed Dec 08, 2010 4:31 pm

Re: Database pagination redirect issue

New postby zzoostmy » Mon Feb 02, 2015 10:16 am

Its nice to hear from you that people are caring in the modern world. Thanking you for info.
zzoostmy
 
Posts: 1
Joined: Mon Feb 02, 2015 10:15 am


Return to Jumi

Who is online

Users browsing this forum: No registered users and 3 guests

cron