Posted by Richard Levasseur on 08/05/06 19:10
David Haynes wrote:
> monomaniac21 wrote:
> > //this loop doesnt work as intended, each row displays twice, once with
> > a number as $key and again with key name as $key!?
> >
> > Any ideas why?
> >
> > $result = mysql_query("SELECT * FROM tbl WHERE id = '1' ");
> > while($row = mysql_fetch_array($result)) {
> >
> >
> > foreach ($row as $key => $value) {
> >
> > echo "<tr><td style='width:150px'>$key</td><td>$value</td></tr>";
> >
> > }
> >
> ...because that's what mysql_fetch_array does. It returns each entry twice.
>
> Change it to mysql_fetch_assoc and see what happens.
>
> -david-
To be more specific, it returns the results both as an indexed and
associative entry.
That means you have a numeric key and a string key for each field.
Change the fetch method or use another function, like
mysql_fetch_assoc()
[Back to original message]
|