You are here: Re: Foreach displaying data twice « PHP Programming Language « IT news, forums, messages
Re: Foreach displaying data twice

Posted by Rami Elomaa on 06/01/07 15:23

Akhenaten kirjoitti:
> I must be missing something rather obvious. I have the following
> snippet of code that echo's my result twice when it should be echoing
> just once (only one element in the array). What am I overlooking?
>
>
> ********************************
> $OpenQ = mysql_query("SELECT column FROM table WHERE q_uid =
> $_SESSION[userid] AND status = 1",$db); // SQL query on DB returns 1
> result
>
> $Qresult = mysql_fetch_array($OpenQ); // Fetch the array

This returns an array that has both index and associative keys. Ie. what
you get is array(0=>'something','column'=>'something');

>
> if ($_GET['OQ']) { // If the get variable is recieved
> foreach ($Qresult as $Q) {

When you loop thru the array, naturally you'll go thru both the index
and the associative key, which both point to the same value. Instead of
foreaching, you could just echo $Qresult[0] or use mysql_fetch_row or
mysql_fetch_assoc.

> echo "<br>" . $Q;
> }
> }
>
> *********************************
>
> TY.
>


--
Rami.Elomaa@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

 

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

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