I've decided to drop foreach altogether now and just used good old while on
its own with a counter to use as the key. The second foreach in your example
would run on each column on the row, when i need to just be able to access
the columns.

I appreciate the help though, thanks ;o)

Am now using:

$key = 0;
while ($row = mysql_fetch_array($result)){
 //stuff accessing $row['id'], $row['blah'] etc...
 $key++;
}

"Marek Kilimajer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> And doesn't this solve your problem? While loop will loop for each row,
> foreach will give you the key and value. How else do you want to loop?
>
> while($row=mysql_fetch_array($result)) {
> foreach($row as $key => $article){
> //here you have $key and $article
> }
> }
>
> Bix wrote:
> > I need to access the row by colum name...
> >
> > eg:
> >
> > $row['id'] $row['title'] $row['detail']
> >
> > My table gen script puts the relelvant fields into the right boxes, and
my
> > maths works from the $key to put <tr>s in the right place.
> >
> > So i need a loop that will loop as many times as there are rows, so
while
> > works fine, but i also need a key, so that is why i wanted to use
> > foreach(mysql_fetch_array($result) as $key => $value) but my problem
arises
> > when i try and access $value in the foreach loop, it is not an array of
the
> > row, but all the values in the row imploded together.
> >
> > "Marek Kilimajer" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> >>Try:
> >>
> >>Bix 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";
> >>
> >>while($row=mysql_fetch_array($result)) {
> >>foreach($row 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

Reply via email to