Jump to content

Pear Paging File


honkmaster

Recommended Posts

Hi I'm trying to paginate results from a query, I have tried to use the Pear Pager file as its quite configurable.

 

I'm stuck at present and keep getting the following error messages (fig1a.png)

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/foscosn1/public_html/cbs/christest.php on line 24

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/foscosn1/public_html/cbs/christest.php on line 25

 

Can anyone point me in the right direction.

 

Also I'm getting a blank line at the top of results in (fig1a) and I can't workout why??

 

Cheers Chris

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="main.css" rel="stylesheet" type="text/css" />
<link href="allother.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
/* Include the Pear::Pager file */
require_once ('Pager/Pager.php');

$con = mysql_connect("localhost","XXXX","XXXX");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("XXXX", $con);

/* First we need to get the total rows in the table */
$result=mysql_query("SELECT COUNT(*) AS total FROM main_data", $connection);
$row = mysql_fetch_array($result);

/* Total number of rows in the logs table */
$totalItems = $row['total'];

/* Set some options for the Pager */
$pager_options = array(
'mode'       => 'Sliding',   // Sliding or Jumping mode. See below.
'perPage'    => 10,   // Total rows to show per page
'delta'      => 4,   // See below
'totalItems' => $totalItems,
);

/* Initialize the Pager class with the above options */
$pager = Pager::factory($pager_options);

/* Display the links */
echo $pager->links;

/* The following code will retreive the result using the pager options */

/* The function below will get the page offsets to be used with
the database query. For e.g if we are on the third page then the
$from variable will have the value of '21' (we are showing 10 items per 
page, remember) and the $to variable will have the value of '30'.
*/
list($from, $to) = $pager->getOffsetByPageId();
/* The MySQL 'LIMIT' clause index starts from '0', 
    so decrease the $from by 1 */
$from = $from - 1;

/* The number of rows to get per query */
$perPage = $pager_options['perPage'];

$result = mysql_query("SELECT orderNumber, dateReceived, status FROM main_data ORDER BY dateReceived LIMIT $from , $perPage");

echo '<table border=0 cellpadding=6 >';
echo '<tr class=tableHead>';
echo '<td>ORDER NUMBER</td><td>DATE RECEIVED</td><td>STATUS</td>';
echo '</tr>';

while($row = mysql_fetch_array($result))
  {
  echo '<tr class=tableBody>';
  echo '<td>' . $row['orderNumber'] . '</td>';
    echo '<td>' . $row['dateReceived'] . '</td>';
  echo '<td>' . $row['status'] . '</td>';
  echo '</tr>';
  }

mysql_close($con);
?>
</body>
</html>

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/195910-pear-paging-file/
Share on other sites

You have an error in your query. It isn't returning a valid resource. Print out $query, execute it in phpmyadmin/mysql. Then you'll know what's the error. You can also give give die(mysql_error()); a try.

 

$result=mysql_query("SELECT COUNT (*) AS total FROM main_data", $connection) or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/195910-pear-paging-file/#findComment-1029081
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.