Re: strings of variables,php, sql

From: Date: Tue, 25 Nov 2003 06:28:47 +0000
Subject: Re: strings of variables,php, sql
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-31734@lists.php.net to get a copy of this message
On Mon, 24 Nov 2003 21:36:29 -0800 (PST) Joffrey Leevy <joffrey_leevy1@yahoo.com> wrote: > Would appreciate in anyone can help me. > > 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; > > 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. > > The problem I have now is with the strings and how do > I see my column values. > > Using echo $$value; or echo $($value) or echo \$$value > or echo $"$value" does not give me the values stored > in the column shed. > > Help anyone? > thanks > Joffrey, First it is easier for us if you just paste the relevant code but I'll try and assist without. Before you can fetch a record you must query the database.. $result=mysql_query($query) or die( "Bad Query=> $query\n<br>". mysql_error() ); The die() function will print an error if there is something wrong with the query such as database not opened first. You are fetching a row (or record) from the database. $row=mysql_fetch_array($result); therefore the value of shed column will be contained within $row. It can be accessed by either of the two lines below. echo $row[0]; #by numeric index.. echo $row["shed"]; #or by column name.. If you wish to find out all the column names and values, try print_r($row); George Patterson

« previous php.db (#31734) next »