Re: $ of variables, php, mysql

From: Date: Tue, 25 Nov 2003 07:28:08 +0000
Subject: Re: $ of variables, php, mysql
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-170854@lists.php.net to get a copy of this message
On Mon, Nov 24, 2003 at 09:42:30PM -0800, Joffrey Leevy wrote: : : Would appreciate in anyone can help me. Some more code would be helpful. : Let's say I do a query in php, eg. $query = "select : shed from structure"; With the mysql_fetch_array : function and a loop I could see all the values stored : in the column, shed, using the command: echo $shed; $query = "select shed from structure"; $result = mysql_query($query); while (($row = mysql_fetch_array($result)) !== false) { echo $row['shed']; } : Let's say now that I am carrying over a variable from : a form called $form where $form = shed. I can still : say $query = "select $form from structure"; because : $form = shed. Try using more variables to make life a little easier to parse: $colname = $_FORM['form'] $query = "select {$colname} from structure"; $result = mysql_query($query); while (($row = mysql_fetch_array($result)) !== false) { echo $row[$colname]; } : The problem I have now is with the strings and how do : I see my column values. Use better variable names. And avoid register_globals.

« previous php.general (#170854) next »