Forum Moderators: coopster
<?php
// Connects to your Database
include 'library/config.php';
include 'library/opendb.php';
// 1. Obtain the required page number
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
// 2. Identify how many database rows are available
$query = "SELECT count(*) FROM table pharmacy";
$result = mysql_query($query, $dbname) or trigger_error("SQL", E_USER_ERROR);
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
// 3. Calculate number of $lastpage
$rows_per_page = 2;
$lastpage = ceil($numrows/$rows_per_page);
// 4. Ensure that $pageno is within range
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
// 5. Construct LIMIT clause
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
// 6. Issue the database query
// Now we can issue the database qery and process the result.
$query = "SELECT id,Code FROM table pharmacy $limit";
$result = mysql_query($query, $dbname) or trigger_error("SQL", E_USER_ERROR);
echo "<table border='1'>";
echo "<tr><th>Id</th><th>Code</th></tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo $row['Code'];
echo "</td></tr>";
}
echo "</table>";
// 7. Construct pagination hyperlinks
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
} // if
include 'library/closedb.php';
?>
this is the /var/log/httpd error:[Wed Nov 29 05:36:51 2006] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected '>' in /home/myname/www/html/tbp/drug/paging-easy.php on line 35
[Wed Nov 29 05:38:09 2006] [error] [client 127.0.0.1] PHP Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/myname/www/html/tbp/drug/paging-easy.php on line 13
[Wed Nov 29 05:38:09 2006] [error] [client 127.0.0.1] PHP Fatal error: SQL in /home/myname/www/html/tbp/drug/paging-easy.php on line 13
[edited by: shams at 12:53 am (utc) on Nov. 29, 2006]
Also, this thread [webmasterworld.com] may be of great help.
If you get the error post it here with it's corresponding line number :)
The other two errors are generated because mysql isn't being initiated correctly (it seems). Check your including db connecting file to make sure everything is correct. Also, instead of using:
or trigger_error("SQL", E_USER_ERROR);
or die(mysql_error());
This will help identify things in the future as well, just remove it after development.
As for the others there is something wrong with your connection to the database, or your query is creating an error. Refer to my previous post for methods to identify mysql errors.
Best of luck!