I think I am seeing double!

Got this code example off of yahoo so consider the source. It works fine and pulls my results from my database except that it prints the results twice. How do I get this to only return the one value?

$currentAd2 = rand (0, 14);

$query = “SELECT towerurl FROM TOWER WHERE id=$currentAd2”;
$result = mysql_query($query);
while ($line = mysql_fetch_array($result))
foreach ($line as $value)
print “$value”;

It’s a little quirk that took me months to figure out :wink:

Say your MySQL table contains the following info:

userid: - username: - email:
1       - myname    - [email protected]

What mysql_fetch_array returns is the following array:

[userid]   => 1
[0]        => 1
[username] => myname
[1]        => myname
[email]    => [email protected]
[2]        => [email protected]

Either that, or the other way around, not sure. But it returns both an associative and an indexed array of your values in the same array, hence all the values are stored twice.

mysql_fetch_assoc() will return the associative array only.

works perfectly, thank you for the help.

Sponsor our Newsletter | Privacy Policy | Terms of Service