Re: What could I be doing wrong here

From: Date: Mon, 26 Mar 2001 23:19:45 +0000
Subject: Re: What could I be doing wrong here
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-45665@lists.php.net to get a copy of this message
In article <99oh2o$f95$1@toye.p.sourceforge.net>, nospam@brochures.co.nz ("YoBro") wrote: > I can't figure out why this doesn't work. Rather than echo $myrow[0] which > works, I want to use the feild name. Like $myrow[make] to make reading the > code easier. IS this possible? > > Here is some code: > > $db = mysql_connect("localhost", $user, $pass)OR DIE("Unable to connect to > database"); > > mysql_select_db("database",$db) OR DIE("Unable to connect to database"); > > $result = mysql_query("SELECT * FROM stock",$db); > > while ($myrow = mysql_fetch_row($result)) > { > echo "$myrow[id]<br>"; //Usually $myrow[0] etc > echo "$myrow[make]<br>"; > echo "$myrow[model]<br>"; > echo "$myrow[sub_model]<br>"; > } Try quoting the index key (which is, after all, a string), and moving the variable outside the double quotes. Since that leaves just plain string text, you might as well turn the remaining double quotes to singles too. Save an extra microsecond or so <g>. echo $myrow['id'] . '<br>'; -- CC

« previous php.general (#45665) next »