Reply to Re: Looping from a fetcharray()

Your name:

Reply:


Posted by Hendri Kurniawan on 07/31/07 22:18

On Aug 1, 8:01 am, Jerim79 <my...@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 =
> mysql_fetch_array($result);
>
> 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=0, x<=$NumRows, x++){
> echo $listings['company_name'];
> }
>
> Any ideas will be greatly appreciated.


You are on the right path, although your syntax is incorrect.

<code>
// Assumes $result is MySQL Result Resource
// Assumes $NumRows has already been populated with number of return
rows
for($x = 0; $x < $NumRows; $x++) {
$listings = mysql_fetch_array($result);
echo $listings['company_name'];
}
</code>


Other method that is shorter:

<code>
// Assumes $result is MySQL Result Resource
while($listing = mysql_fetch_($result)) {
echo $listings['company_name'];
}
</code>

Hendri Kurniawan

[Back to original 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

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