Trying using mysql_fetch_array, and using the field names. This is the
recommended behaviour in PHP4:
$result = mysql_query($myQuery) //$myQuery gets defined earlier
$resultCount = mysql_num_rows($result);
$companyID = array();
while($query_data = mysql_fetch_array($result)) {
$companyID[$query_data['CompanyID']] = $query_data['CompanyName'];
$companyID_string .= "," . $query_data['CompanyID'];
$companyName_string .= "," . $query_data['CompanyName'];
}
That probably isn't the problem, but hey.. you never know.
I also noticed there's no ; after mysql_query ;)
Lastly, you could also do (for debugging):
while ($query_data = mysql_fetch_array($result)) {
$tmp[] = $query_data;
}
echo '<pre>';
ob_start();
print_r($tmp);
$text = ob_get_contents();
ob_end_clean();
echo htmlspecialchars($text);
echo '</pre>';
To see what exactly is being returned.
Mike
Kurt Lieber wrote:
>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
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]