Re: strings of variables,php, sql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



--- George Patterson <george@xxxxxxxxxxx> wrote:
> On Mon, 24 Nov 2003 21:36:29 -0800 (PST)
> Joffrey Leevy <joffrey_leevy1@xxxxxxxxx> 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
> 
Ok, I see, so if the column  name was a variable
called $form passed from a previous page where $form
could hold any value (shed,house,bungalow, etc), then
I could do
echo $row[$form];

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux