RE: [PHP-DB] Stupid newbie looping MySQL question
| From: | Bob Hall | Date: | Sun, 07 Jan 2001 15:22:09 +0000 |
| Subject: | RE: [PHP-DB] Stupid newbie looping MySQL question | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-5672@lists.php.net to get a copy of this message | ||
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";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....[do a bunch more stuff...]
Lynn Siprelle, Siprelle & Associates: Web Construction and Publishing Chief Assoc. Josephine b. 9/9/97 * New Assoc. Louisa due 5/1/01Wean 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