473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Paginating Result Sets

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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}

//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>";
}
}
?>

Aug 31 '06 #1
2 2129
Alec wrote:
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)
There doesn't seem to be any such function. Did you mean
mysql_fetch_object()?

Tim
Aug 31 '06 #2
Tim

Thanks for that. Works a treat now.

Cheers, Alec

Aug 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Darko Jovisic | last post by:
Hi! Another silly question: If a stored procedure returns multiple result sets, how do I choose the one I want to insert into a table? For example sp_spaceused returns two result sets if...
5
by: Stanley Sinclair | last post by:
I have a need to return multiple result sets from a stored procedure. Want that SP to call others to get the data. Win2003, db2 8.1.5. Can't figure out how to handle open cursors, and return...
1
by: Arijit Chatterjee | last post by:
Dear Faculties, I have a query on this statement.. =============================== CREATE PROCEDURE Check_Manage ( ) DYNAMIC RESULT SETS 1 ============================== I want to know the...
3
by: Michael C# | last post by:
Hi all, I'm sending a command via SqlClient, and it returns two result sets. I can successfully read the first result set, but how can I access the second result set? Here's an example of my...
15
by: AussieRules | last post by:
Hi, I have a need to do two selects against to stored proc's in my SQL db. At the moment, each SP is called and two different dataset are populate. Thats two round trips to the SQL server. ...
12
by: urs | last post by:
Hi, please look at the ASP.NET 2 site http://www.prismatest.ch/catalog/EM.ASPX (user=prismashop, password=minicooper). Use the ">" Button to go to the next pages. You will notice that the page...
3
by: esmith2112 | last post by:
Scratching my head on an issue that has been plaguing us ever since we upgraded from version to version 8. Our db2diag file gets inundated with messages that take the form: MESSAGE :...
6
by: happyhondje | last post by:
Hello everyone, I've got a little issue, both programming and performance-wise. I have a set, containing objects that refer to other sets. For example, in a simple notation: (<a, b, c>, <d, e>)...
2
by: Yash | last post by:
Hi, We are in the process of tuning the performance of our stored procs in SQL 2000 and are looking for a tool that would help us in comparing the result sets of an old SP and a modified SP. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.