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

mysql_data_see for for() loops?

Am I right to say mysql_data_seek allows me to walk through a database
return as I would an array?
for ($1=0; $i < $num; $i++) {
mysql_data_see($result, $i);
$row = mysql_fetch_array($results);
}

I still haven't solved the problem I mentioned in another post (I can
only get the first row back from my returns), so I'm tempted to go
this route.
Jul 17 '05 #1
4 1680
lawrence wrote:
Am I right to say mysql_data_seek allows me to walk through a database
return as I would an array? Why???
for ($1=0; $i < $num; $i++) {
mysql_data_see($result, $i);
$row = mysql_fetch_array($results);
}


I suppose you're looking for something like this?

while($row = mysql_fetch_assoc($res))
{
// your code which does anything with $row
}

Just rtfm a little bit...
--> http://php.net/mysql_fetch_array
(Three examples doing this.)
Jul 17 '05 #2
On 2004-03-05, lawrence wrote:
Am I right to say mysql_data_seek allows me to walk through a database
return as I would an array?
for ($1=0; $i < $num; $i++) {
mysql_data_see($result, $i);
$row = mysql_fetch_array($results);
}

I still haven't solved the problem I mentioned in another post (I can
only get the first row back from my returns), so I'm tempted to go
this route.


mysql_data_seek lets you move the array pointer to the specified point.
Why not just use:

while ( $row = mysql_fetch_array($results)) {
// Do your stuff
}

?

--
Mike Peters
mike [-AT-] ice2o [-DOT-] com
http://www.ice2o.com
Jul 17 '05 #3
Mike Peters <o0****************@THIShotmail.com> wrote in message news:<1d******************************@news.terane ws.com>...
mysql_data_seek lets you move the array pointer to the specified point.
Why not just use:

while ( $row = mysql_fetch_array($results)) {
// Do your stuff
}


Because that would mean using msyql specific commands in the main part
of my code. I've masked out all the mysql stuff. I've a selectObject
that all queries get run through. It might be getting data from mysql
or postgre or a file or an xml stream. The code doesn't know where the
data comes from. So my loop looks like this:
$selectObject->setQuery("GetAllWeblogEntries");
$selectObject->getData();
$howMany = $selectObject->getCount();

for ($i=0; $i < $howMany; $i) {
$row = $selectObject->getNextRow();
}

This was working perfectly till this week, when I made some changes
and busted it. I'm not sure what I did wrong. The getCount method
still works correctly and returns the correct number of items that
have been returned. But then in the for() loop, the getNextRow()
method only works the first time. After that it returns nothing. I'm
very confused by this - I'd think either the pointer would advance to
the next row, or it would stay stuck on the first row and return that
for how ever many times $howMany equals. But instead it works once and
then returns nothing. However, it remains a valid resource pointing to
a database return. I know this because inside of getNextRow the result
pointer gets tested every time with is_resource($results) and it never
tests false. So I'm confused about what is going on.

Today, in desperate attempt to get the code working again, I changed
things so that I could pass the loop index into getNextRow and feed it
to mysql_data_seek. But it still didn't work. This is what I'm
currently trying:
$selectObject->setQuery("GetAllWeblogEntries");
$selectObject->getData();
$howMany = $selectObject->getCount();

for ($i=0; $i < $howMany; $i) {
$row = $selectObject->getNextRow($i);
}


then, inside getNextRow(), I go:

if (is_resource($result)) {
$success = mysql_data_seek($result, $i);
if ($success) {
$resultsObject->debugNotes("Tested true");
} else {
$resultsObject->addToErrorResults("Tested false");
}
}

And it keeps testing false. I'm a little stunned by this. Why is
mysql_data_seek() failing if the resource is testing true in
is_resource()? I'm having a damned hard time figuring it out.

I also echo out the actual query to the screen and then run it through
phpMyAdmin so I can see what kind of return I should expect. All day
I've been running my tests on one query where I know I should be
getting back 3 entries. phpMyAdmin tells me so and the method
getCount() correctly comes back with 3. And, as I said, the first row
comes back fine. After that nothing works.

I'm passing the resource pointer by reference, so what happens inside
the object should effect what happens outside.
Jul 17 '05 #4
lawrence wrote:
This was working perfectly till this week, when I made some changes
and busted it. I'm not sure what I did wrong.
Since I discovered CVS I wonder how I was able to do anything at all
without using it :-)

There's a more recent thing called "SVN" (if I remember correctly)
which I haven't yet tried out.
[...]
then, inside getNextRow(), I go:

if (is_resource($result)) {
$success = mysql_data_seek($result, $i);
if ($success) {
$resultsObject->debugNotes("Tested true");
} else {
$resultsObject->addToErrorResults("Tested false");
}
}

And it keeps testing false. I'm a little stunned by this. Why is
mysql_data_seek() failing if the resource is testing true in
is_resource()? I'm having a damned hard time figuring it out.
Test the return value from all mysql_* functions with mysql_error().

$success = mysql_data_seek($result, $i);
if ($success) {
$resultsObject->debugNotes("Tested true");
} else {
$resultsObject->addToErrorResults("Tested false with " . mysql_error());
}
I also echo out the actual query to the screen and then run it through
phpMyAdmin so I can see what kind of return I should expect. All day
I've been running my tests on one query where I know I should be
getting back 3 entries. phpMyAdmin tells me so and the method
getCount() correctly comes back with 3. And, as I said, the first row
comes back fine. After that nothing works.


Do you have error_reporting set to show all errors, warnings and
notices?
I have php.ini configured to *not* show any errors and save them to a
error log. However, when I'm having trouble with a script I do a

define('DEBUG', '1');

before requiring my standard include file, which has

if (DEBUG) {
error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('error_log', '');
}

I find it much easier to see the errors in the browser than having to
open the error log.
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #5

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

Similar topics

3
by: Oleg Leschov | last post by:
Could there be means of exiting nested loops in python? something similar to labelled loops in perl.. I consider it irrating to have to make a flag for sole purpose of checking it after loop if...
15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
4
by: Dr. David Kirkby | last post by:
I have a program that loops through and changes all the elements on an array n times, so my code looks like this: for (n=1; n < n_max; ++n) for(i=imax; i >= 0; --i) { for(j=0 ; j < jmax; ++j) {...
6
by: Scott Brady Drummonds | last post by:
Hi, everyone, I was in a code review a couple of days ago and noticed one of my coworkers never used for() loops. Instead, he would use while() loops such as the following: i = 0; while (i...
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
10
by: Putty | last post by:
In C and C++ and Java, the 'for' statement is a shortcut to make very concise loops. In python, 'for' iterates over elements in a sequence. Is there a way to do this in python that's more concise...
2
by: bitong | last post by:
I'm a little bit confuse with regard to our subject in C..We are now with the Loops..and I was just wondering if given a problem, can you use Do-while loops instead of a for loops or vise versa? are...
3
by: monomaniac21 | last post by:
hi all i have a script that retrieves rows from a single table, rows are related to eachother and are retrieved by doing a series of while loops within while loops. bcos each row contains a text...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.