You are here: Re: why does foreach display each loop twice « PHP Programming Language « IT news, forums, messages
Re: why does foreach display each loop twice

Posted by David Haynes on 08/04/06 10:46

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-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация