Re: [PHP-DB] strings of variables,php, sql

2003-11-25 Thread Joffrey Leevy

--- George Patterson <[EMAIL PROTECTED]> wrote:
> On Mon, 24 Nov 2003 21:36:29 -0800 (PST)
> Joffrey Leevy <[EMAIL PROTECTED]> 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".
> 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



Re: [PHP-DB] strings of variables,php, sql

2003-11-24 Thread George Patterson
On Mon, 24 Nov 2003 21:36:29 -0800 (PST)
Joffrey Leevy <[EMAIL PROTECTED]> 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".
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

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



[PHP-DB] strings of variables,php, sql

2003-11-24 Thread Joffrey Leevy
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

__
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



[PHP-DB] Strings

2001-03-19 Thread Mick Lloyd

CC/Steve

Thanks for the advice. I managed to get the "... Code =
'".$row['Primaryexpertise']."'" option working but not the others. Thanks
again.

Regards

Mick Lloyd
[EMAIL PROTECTED]
Tel: +44 (0)1684 560224



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] Strings

2001-03-19 Thread Steve Brett



$row[Primaryexpertise] //not like this
$row['Primaryexpertise'] //like this
$row["Primaryexpertise"] //or like this

>i always user double quotes with postgrtesql and it works like a treat.
> the difference seems to be with mysql.

Also, even though simple variable references are expanded within 
double-quotes (ex. "where Profileid = '$profileid'"), the PHP parser seems 
to be less certain about how to deal with array indexes: is the square 
bracket intedned as plain text, as a special character (such as in a 
regular expression) or is it actually an array index?  I find that dropping 
out of quotes whenever referencing array indexes eliminates a lot of parse 
errors.  For example:

"select Primaryid from primarycodes where Code = '" . 
$row['Primaryexpertise'] . "'"

Another option is to use extract() so that the array element can be treated 
as a simple string variable:

extract($row);
$result = mysql_query("select Primaryid from primarycodes where Code =
'$Primaryexpertise'")

> String manipulation has me baffled most of the time!

Re-read the manual's chapters on strings and arrays.  Also check out the 
Zend site.  There are some interesting articles and tutorials over there 
that address issues not yet adequately covered in the manual.

-- 
CC

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Strings

2001-03-18 Thread CC Zona

In article <003801c0afa2$2d5853e0$890083ca@oemcomputer>,
 [EMAIL PROTECTED] ("Mick Lloyd") wrote:

> Can anyone advise on how to surround a string variable in a query. I select
> a string code from a column using:
> 
> $result = mysql_query("SELECT * FROM $TA WHERE Profileid = '$profileid'");
> $row = mysql_fetch_array($result);
> 
> I then want to extract from a second table an id  that relates to the code
> from the first query. I've tried various combinations of:
> 
> $result = mysql_query("select Primaryid from primarycodes where Code =
> '$row[Primaryexpertise]'")

Associate array indexes should be quoted:

$row[Primaryexpertise] //not like this
$row['Primaryexpertise'] //like this
$row["Primaryexpertise"] //or like this

Also, even though simple variable references are expanded within 
double-quotes (ex. "where Profileid = '$profileid'"), the PHP parser seems 
to be less certain about how to deal with array indexes: is the square 
bracket intedned as plain text, as a special character (such as in a 
regular expression) or is it actually an array index?  I find that dropping 
out of quotes whenever referencing array indexes eliminates a lot of parse 
errors.  For example:

"select Primaryid from primarycodes where Code = '" . 
$row['Primaryexpertise'] . "'"

Another option is to use extract() so that the array element can be treated 
as a simple string variable:

extract($row);
$result = mysql_query("select Primaryid from primarycodes where Code =
'$Primaryexpertise'")

> String manipulation has me baffled most of the time!

Re-read the manual's chapters on strings and arrays.  Also check out the 
Zend site.  There are some interesting articles and tutorials over there 
that address issues not yet adequately covered in the manual.

-- 
CC

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Strings

2001-03-18 Thread Mick Lloyd

Can anyone advise on how to surround a string variable in a query. I select
a string code from a column using:

$result = mysql_query("SELECT * FROM $TA WHERE Profileid = '$profileid'");
$row = mysql_fetch_array($result);

I then want to extract from a second table an id  that relates to the code
from the first query. I've tried various combinations of:

$result = mysql_query("select Primaryid from primarycodes where Code =
'$row[Primaryexpertise]'")

 with =, ==,  ===, ', \",  but always get a syntax error. I can get it to
work with LIKE as follows:

$result = mysql_query("select Primaryid from primarycodes where Code like
'%$row[Primaryexpertise]%'")

but I need greater accuracy because some codes contain similar data. String
manipulation has me baffled most of the time!

Thanks.

Mick Lloyd
[EMAIL PROTECTED]
Tel: +44 (0)1684 560224


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]