472,972 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,972 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 1666
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.