Duplicate value returned even though there is only 1 value

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
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Duplicate value returned even though there is only 1 value

Post 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";
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your query would suggest there are two, duplicate records.
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Post by shab620 »

hye

There is only one record in the mysql database
any other ideas?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

post what is being shown, please.
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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:
shab620
Forum Commoner
Posts: 48
Joined: Tue Jan 18, 2005 7:50 pm

Post 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
Post Reply