You are here: Re: Looping from a fetcharray() « PHP Programming Language « IT news, forums, messages
Re: Looping from a fetcharray()

Posted by Rik on 07/31/07 22:10

On Wed, 01 Aug 2007 00:01:03 +0200, Jerim79 <mylek@hotmail.com> wrote:

> I have a SQL query that returns all company names containing a user
> defined keyword. I store all this information using: $listings =3D
> mysql_fetch_array($result);

Nope: unless this is part of a loop, you store 1 row of the result in =

$listings.

> That query works fine, as I am able to see the first company. What I
> need to do, is loop through the array, displaying each company name. I=

> have the code to write the company name to the screen. I am just
> trying to figure out how to do the loop. My beta attempt:
>
> (Not shown is that I have used $NumRows to catch the number of rows
> contained in $result)
>
> for (x=3D0, x<=3D$NumRows, x++){
> echo $listings['company_name'];
> }

Try the manual, an excellent example of widely used code:
<http://www.php.net/mysql_fetch_array>

while ($row =3D mysql_fetch_array($result)) {
print_r($row);
}

The fact is, mysql_query() returns a result-resource, mysql_fetch_array(=
) =

returns one row from that result, so you'll have to loop it untill $row =
=

doesn't get an array from mysql_fetch_array() anymore (or earlier if the=
=

code might ask for that).
-- =

Rik Wasmus

 

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

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