Re: How do you define table row indexes?

From: Date: Tue, 27 Mar 2001 17:10:28 +0000
Subject: Re: How do you define table row indexes?
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-7889@lists.php.net to get a copy of this message
In article <7527893368A6D311A6B2009027DC765B1DCF20@exchange.hq.ssai.com>, Anyangwe@SSAI.com ("Anyangwe, Tanwani") wrote: > $result = mysql_query("SELECT * FROM motor_vehicle",$db); > $strSep = '&nbsp;|&nbsp;'; > while ($myrow = mysql_fetch_array($result)) > { > echo $myrow['id'].$strSep; > } > > Gives me the following error: > > Warning: Undefined index: id in C:\PHP\Test_Scripts\testdb2.php on line 16 1) It's not considered a good habit to use "select *" in scripts. When you later modify the table defs, your scripts will be blown. Even if you never add/drop/change a column, it's still messy since whenever you're working on the code you have to remember--accurately--all of the columns and exactly (case_sensitive_ what they are named. Yuck. Much cleaner to include the column names in your query now. "Select id from motor_vehicle"--then you know for sure you're working with a column of that name. 2) mysql_fetch_array doesn't fetch NULLs. If the value of column 'id' in a given row is NULL, then $myrow['id'] will be undefined for that row. See <http://php.net/manual/en/function.mysql-fetch-array.php>. -- CC

« previous php.db (#7889) next »