Page 1 of 1

double results from db query when doing fetch_array

Posted: Sat May 27, 2006 3:59 pm
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

Posted: Sat May 27, 2006 4:04 pm
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.