double results from db query when doing fetch_array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tbbd
Forum Newbie
Posts: 20
Joined: Sat Apr 22, 2006 2:54 pm

double results from db query when doing fetch_array

Post by tbbd »

I have tried this with several different tables, querries, etc, and I always get double results
For this example, I have a db table that has id, name for the fields and has 5 rows
I do this query

Code: Select all

$query = mysql_query("select * from table1 where id='4'");
$tables = mysql_fetch_array($query);
foreach( $tables as $name )
{
	echo "<br>".$name;
}
This is what is output:

Code: Select all

4
4
Name4
Name4
No idea why it gives a double result for each entry
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the "double" is due to the array result being returned by mysql_fetch_array() not the database. The function normally returns both named and numeric indexed entries.
Post Reply