Posted by Alec on 08/31/06 10:18
First attempt at doing an exercise on paginating result sets
When I run the code, I receive the error "Fatal error: Call to
undefined function: mysql_fetch_objects() in
/homepages/17/d23395818/htdocs/en/test.php on line 48"
Line 48 is while($row = mysql_fetch_objects($result)) Any ideas?? Have
I missed an obvious mistake. (full code below)
Many thanks
Alec
<?php
//sets number of records and ref number in database to search by
$records_per_page = 2;
$search = "123-456-BSE";
//look for starting marker
(!$_GET['start']) ? $start = 0 : $start = $_GET['start'];
$connection = @mysql_connect('???', '???', '???');
if (!$connection) {
echo '<p>Unable to make database connection.</p>';
exit();
}
if (!@mysql_select_db('???')) {
exit('<p>Unable to locate database.</p>');
}
//create and execute query to count records
$query = "SELECT COUNT(*) FROM schott_news WHERE userID='$search'";
$result = mysql_query($query);
//get total number of records
$row = mysql_fetch_row($result);
$total_records = $row[0];
//if records exist
if (($total_records > 0) && ($start < $total_records))
{
//create and execute query to get batch of records
$query = "SELECT userID, username FROM schott_news WHERE
userID='$search' LIMIT $start, $records_per_page";
$result = mysql_query($query);
//iterate over record set and print data
echo '<table border=1 cellpadding=10>';
while($row = mysql_fetch_objects($result))
{
echo '<tr>';
echo "<td>$row->userID</td>";
echo "<td>$row->username</td>";
echo '<tr>';
}
echo '</table>';
//set up previous page
if ($start >= $records_per_page)
{
echo "<a href=" . $_SERVER['PHP_SELF'] .
"?start=" . ($start-$records_per_page) . ">Previous
Page</a> ";
}
//setup next page
if ($start+$records_per_page < $total_records && $start >= 0)
{
echo "<a href=" . $_SERVER['PHP_SELF'] .
"?start=" . ($start+$records_per_page) . ">Next Page</a>";
}
}
?>
[Back to original message]
|