You are here: Re: php and MySQL error « PHP Programming Language « IT news, forums, messages
Re: php and MySQL error

Posted by Rik on 03/06/07 07:50

gcox<add the at symbol in <"here>freeuk.com"> wrote:
> just as a matter of interest! I have the
>
> while ($row[] =3D mysql_fetch_array($result)) {
> printf("<td valign=3D'top'><strong>Venue</strong></td><td _ =

> valign=3D'top'>%s &nbsp;</td></tr>",$row[0]["venue"]);
>
> ie $row[] and
> $row[0]["venue"]
>
> typeof code on another web site and it seems to work OK. What is the
> difference between thie above and using
>
> $row and $row["venue"] ??

$row[] =3D will add the result as an array to the array $row.

So if the result of mysql_fetch_array() is:
array('id' =3D> '123','venue' =3D> 'the shed');

$row[] =3D mysql.... will result in $row being:

array(
0 =3D> array('id' =3D> '123','venue' =3D> 'the shed'));
(and running is again would result in $row being:
array(
0 =3D> array('id' =3D> '123','venue' =3D> 'the shed')
1 =3D> array('id' =3D> '456','venue' =3D> 'under the couch'));

=

$row =3D mysql.... will result in $row being:
array('id' =3D> '123','venue' =3D> 'the shed'));

And overwrite $row with the following results on every loop.

The [] is often used when the result has to be looped several times, or =
=

the entire resultset has to be passed as an array to another piece of co=
de.

Using $row[0]["venue"] is only usefull if you're only interested in the =
=

first result (in which case the while loop is unneccesary overhead).
-- =

Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel

 

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

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