This is correct:
while($myrow = mysql_fetch_array($result))
{
// ...
}
The iteration of the while loop represents one returned row from the mysql
result, with $myrow being an array of values returned.
Rather than a SELECT * query, let's look at a something where we know the
column names:
<?
$sql = "
SELECT first, surname, age
FROM employee
WHERE age >= 18
LIMIT 50
";
$result = mysql_query($sql);
while($myrow = mysql_fetch_array($result))
{
echo "Name: {$myrow['first']} {$myrow['surname']}. Age:
{$myrow['age']}<br />";
}
?>
Now, given the above code, what else do you need to do?
Justin
on 03/06/03 8:25 AM, Bix ([EMAIL PROTECTED]) wrote:
> Hi all,
>
> I am trying to build up a table using values from a db as follows...
>
> mysql_select_db($db, $sql_connection);
> $result = mysql_query("SELECT * FROM $table WHERE $query LIMIT
> $limit",$sql_connection);
> $output = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"
> width=\"370\">\n";
> foreach(mysql_fetch_array($result) as $key => $article){
> //stuff
> }
>
> now if I use a while loop ie:
>
> while ($array = mysql_fetch_array($result)){
> //stuff
> }
>
> all the matched rows are processed, however with the foreach model, $article
> isnt an array, it is the first row all merged together.
>
> Any ideas?
>
> ;o)
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php