|
|
|
|
|
|
| Author |
Message |
yusufm *nix forums addict
Joined: 27 Feb 2006
Posts: 52
|
Posted: Tue Jul 18, 2006 7:01 pm Post subject:
How to add variables to strings?
|
|
|
Hi,
I want to construct a SQL statement which consists of a string added to
some information stored in variables. But its not adding the text of
the variable to the first part of the string, just storing the value of
the variable:
$statement = "select * FROM logarama WHERE timestamp > ". $T[4]+1 |
|
| Back to top |
|
 |
Paul Lalli *nix forums Guru
Joined: 10 Jun 2005
Posts: 1089
|
Posted: Tue Jul 18, 2006 7:14 pm Post subject:
Re: How to add variables to strings?
|
|
|
yusuf wrote:
| Quote: | Hi,
I want to construct a SQL statement which consists of a string added to
some information stored in variables. But its not adding the text of
the variable to the first part of the string, just storing the value of
the variable:
$statement = "select * FROM logarama WHERE timestamp > ". $T[4]+1
|
Running the above through -MO=Deparse,-p gives us:
$ perl -MO=Deparse,-p -e'$statement = "select * FROM logarama WHERE
timestamp > " . $T[4]+1;'
($statement = (('select * FROM logarama WHERE timestamp > ' . $T[4]) +
1));
-e syntax OK
As the above shows, . has a higher precedence than +. So you are
contatenating $T[4] to the string literal, and then adding 1 to the
result. Put parentheses around your addition expression:
$statement = "select * FROM logarama WHERE timestamp > " . ($T[4]+1);
Paul Lalli |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Jan 08, 2009 7:03 am | All times are GMT
|
|
Loans | School Girl Costumes | Credit Cards | Best Credit Cards | Loans
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|