Page 1 of 1

Duplicate value returned even though there is only 1 value

Posted: Tue Jan 18, 2005 7:56 pm
by shab620
Hye
I'm having a small problem
I'm attempting to query a mysql database using php. the problem is that there is only one record in the database table but even still i get two records of the same displayed in my browser. Does anyone have any ideas on how to fix this?
The code for the query is as follows:

mysql_select_db("coachhouse",$connection);
$result = mysql_query ("SELECT * FROM specials",$connection);
while ($row = mysql_fetch_array($result))
{
foreach ($row as $attribute)
PRINT "{$attribute} ";
PRINT "\n";
}

Posted: Tue Jan 18, 2005 8:08 pm
by feyd
your query would suggest there are two, duplicate records.

Posted: Tue Jan 18, 2005 8:30 pm
by shab620
hye

There is only one record in the mysql database
any other ideas?

Posted: Tue Jan 18, 2005 8:34 pm
by feyd
post what is being shown, please.

Posted: Tue Jan 18, 2005 8:38 pm
by shab620
hello again

this is what is returned in my browser

1 1 Sweet and Sour Rice served with hot sauce and noodles Sweet and Sour Rice served with hot sauce and noodles 2001-01-05 2001-01-05 10 10


there atre four fields in the table

as you can see they repeat them selves. but only one record in the table.

Posted: Tue Jan 18, 2005 8:48 pm
by feyd
oh.. silly me.. of course.. mysql_fetch_array() returns 2 elements for every column.. first by numeric index, then by named index.

you should be using mysql_fetch_assoc() or mysql_fetch_row().

:oops:

Posted: Tue Jan 18, 2005 8:57 pm
by shab620
Spot on

has worked now

thank you for that, You'll probably be seeing more of my posts, lol as i'm doing this project for a university module.

Regards
shab