while() looping over query results twice?
| From: | Kurt Lieber | Date: | Thu, 25 Oct 2001 19:51:10 +0000 |
| Subject: | while() looping over query results twice? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-72337@lists.php.net to get a copy of this message | ||
I'm executing a query that returns some a UID and a company name. I'm using
the following code to loop over that query result set:
$result = mysql_query($myQuery) //$myQuery gets defined earlier
$resultCount = mysql_num_rows($result);
$companyID = array();
while($query_data = mysql_fetch_row($result)) {
$companyID[$query_data[0]] = $query_data[1];
$companyID_string .= "," . $query_data[0];
$companyName_string .= "," . $query_data[1];
}
I've used $resultCount to verify the query is returning 4 rows. However, the
while loop above is looping over the results twice -- $companyID_string and
$companyName_string each have 8 values. Looking at the values shows that
it's the 4 rows duplicated.
What the heck am I doing wrong?
--kurt