Justtechjobs.com Find a programming school near you






Online Campus Both


php-db | 2001011

RE: [PHP-DB] Stupid newbie looping MySQL question From: Bob Hall (rjhalljr <email protected>)
Date: 01/07/01

Ma'am, I'm not an expert on the inner workings of PHP, but here's
what I think is happening.

>$result = mysql_query ("Select name from mytable");

The result table (the results of the query) is loaded into a buffer,
which is pointed to by $result.

>while ($row = mysql_fetch_array ($result)) {

$row is assigned the first row of the result table. I suspect that
this runs successfully once.

> $newTableName = $row['0'];
> $sSQL = "Select id,thread,subject,author,datestamp from
>$newTableName order by datestamp desc limit 30";
> ...[do a bunch more stuff...]

And in the bunch more stuff, you run another mysql_query(), which
replaces the result table in the buffer with the result table from
the new query. If the result of the second query is assigned to a
variable other than $result, then $result now points to a nonexistent
result table. On the second pass through the while loop,
mysql_fetch_array($result) returns an error, because there is no
longer anything to fetch.

Look at it this way. You had to wait until you had finished running
fetch_baby(Josephine) before you could start running
fetch_baby(Louisa).
There's only one buffer!

If I am correct, then the solution is to load the result table from
the first query into the array $rows, and then process the result
array to extract the data for your second query.

>Lynn Siprelle, Siprelle & Associates: Web Construction and Publishing
>Chief Assoc. Josephine b. 9/9/97 * New Assoc. Louisa due 5/1/01

Wean them on Unix. Windows will cripple their social development.
Imagine the trauma of a 2 year old shunned by the other children
because she can't grep a text file!

There have been warnings that excessive exposure to computers too
early can skew a person's perception of reality as an adult. But I
don't know of any cases where this has actually happened.

Bob Hall

Know thyself? Absurd direction!
Bubbles bear no introspection. -Khushhal Khan Khatak

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-db-unsubscribe <email protected>
For additional commands, e-mail: php-db-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>