473,387 Members | 1,548 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,387 software developers and data experts.

mysql_fetch_row() after mysql_data_seek()

Yesterday, I ran into a problem that seems to stem from an unusual
behavior of mysql_fetch_row() and mysql_fetch_assoc(). Specifically, I
have a query that selects all of the id's of fields matching certain
criteria, and I want to then fetch the complete results of a certain
subset of those fields, depending on the current result page and number of
records to show per page. The original code looked like this:

mysql_data_seek($this->query, ($this->page - 1) * $this->limit);
for ($i = 0; $i < $this->limit; $i++) {
$result = mysql_fetch_assoc($this->query);
// The get() method fetches the complete record
$this->results[] = $this->get($result[$this->key]);
}

Unfortunately, this did not work as expected. This either returned the
same row every time, or, if I wrote the loop differently, returned one
result and then quit. It appears that after calling mysql_data_seek,
mysql_fetch_assoc does not advance the result pointer. However, I couldn't
find this documented anywhere.

My temporary solution also ran into PHP's apparent lack of a C-style break
or Perl-style last statement. Does such a thing exist, or am I correct in
having to write something like:

for ($i = 0; $i < $this->limit; $i++) {
// blah blah blah
// Force break out of loop
if ($row = mysql_num_rows($this->query) {
$i = $this->limit;
}
}

Thanks in advance--

Jesse S. Bangs ja****@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
Jul 16 '05 #1
1 3476
Andy Hassall sikyal:
On Mon, 21 Jul 2003 11:13:03 -0700, JS Bangs <ja****@u.washington.edu> wrote:
Yesterday, I ran into a problem that seems to stem from an unusual
behavior of mysql_fetch_row() and mysql_fetch_assoc(). Specifically, I
have a query that selects all of the id's of fields matching certain
criteria, and I want to then fetch the complete results of a certain
subset of those fields, depending on the current result page and number of
records to show per page. The original code looked like this:

mysql_data_seek($this->query, ($this->page - 1) * $this->limit);
for ($i = 0; $i < $this->limit; $i++) {
$result = mysql_fetch_assoc($this->query);
// The get() method fetches the complete record
$this->results[] = $this->get($result[$this->key]);
}

Unfortunately, this did not work as expected. This either returned the
same row every time, or, if I wrote the loop differently, returned one
result and then quit. It appears that after calling mysql_data_seek,
mysql_fetch_assoc does not advance the result pointer. However, I couldn't
find this documented anywhere.


Can't reproduce the problem here; given a table 'seektest (c int)' populated
with 1-10, the following works as expected:
[snip working example]

What's the definition of $this->get? Are you perhaps stomping on some
variables within that?


This is a possibility. $this->get does indeed overwrite $this->query, but
in my real code (not the trimmed version I posted) I'm accomodating for
that. But perhaps my original code didn't do this. I'm working from memory
here, since I've replaced the code block in question with something
hackish that works, and on this small project I'm not using CVS and so
can't fetch and earlier version :-). I'll test again and repost.
My temporary solution also ran into PHP's apparent lack of a C-style break
or Perl-style last statement. Does such a thing exist,


http://uk.php.net/break


Well, that's a releif. I'm sure that I searched php.net for that, but must
have missed it somehow (which is strange, since it pops right up *now* . .
..)

--
Jesse S. Bangs ja****@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"
Jul 16 '05 #2

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

Similar topics

2
by: Tony W. | last post by:
I am trying to do something in PHP that I thought would be fairly easy but has become rather troublesome. I'm trying to retrieve a list of numbers from a MySQL database and display the contents...
0
by: lawrence | last post by:
This is a follow up to my last post. I've been working trying to figure this out, to no avail. I've made it so that I could pass an index down and use mysql_data_seek to force the database resource...
2
by: pancho | last post by:
Greetings, I need help configuring/building PHP3 with MySQL as a DSO on a Solaris 8 box - this module is needed to host some existing sites I will be migrating Note. I built PHP4 from source and...
4
by: Stefan van Roosmalen | last post by:
Hi there, I am using some example PHP code to build a counter for a page on my webserver. When going to that page, I will see the following error message: Warning: mysql_fetch_row(): supplied...
4
by: Mark Wilson CPU | last post by:
A colleague has written a prototype program in PHP, using a MySQL database. It's a relatively simple app, with a restricted set of mysql commands used (see below). The MySQL DB is being replaced...
4
by: nizar.jouini | last post by:
OK... The point is to make links in the end of each row just like in PHPMyAdmin. So after every row there would be links to delete row(delete row from database) update row (update row from...
0
by: sherlockweb | last post by:
Does anyone know if there is a equiavalent method to the mysql_data_seek() function call to reset a result set in PDO?
7
by: wingsss | last post by:
i am currently using WindowsXP SP2 all updated apache 2.2.4 PHP 5.2.3 MySQL 5.0 and apache hang up when running this code //...
1
by: Jason Carlton | last post by:
I'm needing to traverse my $sth twice: list($date_found, $junk) = mysql_fetch_row($sth); while (list($date, $stuff1, $stuff2) = mysql_fetch_array($sth)) { // do stuff } But of course, when...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.