Forum Moderators: coopster

Message Too Old, No Replies

paging code problem?

         

shams

12:44 am on Nov 29, 2006 (gmt 0)

10+ Year Member



hi,
i got this paging code for php-mysql from a site, and edit for my pahramcy table but output is a blank page, where is the error please:

<?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]

eelixduppy

12:50 am on Nov 29, 2006 (gmt 0)



Try increasing your error_reporting or check your error logs. Report any errors that you are getting. What is happening is PHP is experiencing a fatal error.

Also, this thread [webmasterworld.com] may be of great help.

If you get the error post it here with it's corresponding line number :)

eelixduppy

1:49 am on Nov 29, 2006 (gmt 0)



ok then... The first error is a syntax error. After skimming the code I can't seem to locate it; can you give me line 35, please?

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);

use:

or die(mysql_error());

This will help identify things in the future as well, just remove it after development.

shams

2:06 am on Nov 29, 2006 (gmt 0)

10+ Year Member



thanks for replies these are the error lines:
LINE 13: $result = mysql_query($query, $dbname) or trigger_error("SQL", E_USER_ERROR);
LINE 35: echo "<tr><td>";

eelixduppy

9:32 pm on Nov 29, 2006 (gmt 0)



The error at line 35 doesn't make any sense. There is something missing here...

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!