[PHP] Variable names
If I have a variable, how do I extract the name of the variable. In principle: $varname=somefunction($myvar); The value of $varname is then "myvar" How do I do it? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variable Appended To The End of a URL Is Not Working in SQL Query
Jason means that you should execute it from the mysql command line; In your PHP code: print $sql. Then copy from that window and paste into mysql command line and execute. What are the results? -Original Message- From: Dr. Shim [mailto:[EMAIL PROTECTED]] Sent: Monday, April 01, 2002 10:48 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Variable Appended To The End of a URL Is Not Working in SQL Query Hmm, run it manually? I'm a newbie, so, could you explain how I'd do that? =) "Jason Murray" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'd say $id is blank, not being passed in, or is equal to a nonexistant IDArt. Maybe you should echo out your SQL and run it manually to see what's going on. J -- Jason Murray [EMAIL PROTECTED] Web Developer, Melbourne IT "Work now, freak later!" > -Original Message- > From: Dr. Shim [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, April 02, 2002 2:41 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Variable Appended To The End of a URL Is Not Working in > SQL Query > > > I have a variable which is appeneded to the end of a URL, like > > http://www.your_web_site.com/your_page/?your_variable=your_value > > This would return "your_value"; > > echo $your_variable; > > But this wouldn't work, and returns an error > > $sql = "SELECT * FROM fldField WHERE IDField = " . $id; > > > What could possibly be wrong? If you need more info, then > tell me. Here's my > code: > > $db = @odbc_connect('ReviewDatabase', 'root', '') or exit)("Error > occured:$php_errormsg"); > $sql = "SELECT * FROM tblArt WHERE IDArt = $id"; > $cursor = @odbc_exec($db, $sql) or exit ("Error > occrued:$php_errormsg"); > odbc_close($db); > ?> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable Appended To The End of a URL Is Not Working in SQL Query
The "your_variable" thing was just an example. It actually uses $id (an a real URL). "Tyler Longren" <[EMAIL PROTECTED]> wrote in message 003001c1da02$f46e65b0$0101a8c0@nightengale">news:003001c1da02$f46e65b0$0101a8c0@nightengale... Well, there's not $id variable. And you're trying to select it. Should be this: $php_errormsg"); // next line has changed $sql = "SELECT * FROM tblArt WHERE IDArt = $your_variable"; $cursor = @odbc_exec($db, $sql) or exit ("Error occrued:$php_errormsg"); odbc_close($db); ?> Tyler Longren Captain Jack Communications [EMAIL PROTECTED] www.captainjack.com - Original Message - From: "Dr. Shim" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, April 01, 2002 10:41 PM Subject: [PHP] Variable Appended To The End of a URL Is Not Working in SQL Query > I have a variable which is appeneded to the end of a URL, like > > http://www.your_web_site.com/your_page/?your_variable=your_value > > This would return "your_value"; > > echo $your_variable; > > But this wouldn't work, and returns an error > > $sql = "SELECT * FROM fldField WHERE IDField = " . $id; > > > What could possibly be wrong? If you need more info, then tell me. Here's my > code: > > $db = @odbc_connect('ReviewDatabase', 'root', '') or exit)("Error > occured:$php_errormsg"); > $sql = "SELECT * FROM tblArt WHERE IDArt = $id"; > $cursor = @odbc_exec($db, $sql) or exit ("Error > occrued:$php_errormsg"); > odbc_close($db); > ?> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable Appended To The End of a URL Is Not Working inSQL Query
On Mon, 1 Apr 2002, Dr. Shim wrote: > I have a variable which is appeneded to the end of a URL, like > > http://www.your_web_site.com/your_page/?your_variable=your_value > > This would return "your_value"; > > echo $your_variable; > > But this wouldn't work, and returns an error > > $sql = "SELECT * FROM fldField WHERE IDField = " . $id; Consider yourself lucky. Taking a variable supplied by a user and dumping it into a SQL query like that is basically the same as printing your database password on your front page. If it's a number, take intval() of it. If it's a string, addslashes() it or make sure that magic_quotes_gpc is on. And take your user-posted variables from $_REQUEST rather than from the variables that get created automatically (which you should turn off unless you REALLY know what you're doing because it's a dangerous feature). miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable Appended To The End of a URL Is Not Working in SQL Query
Well, there's not $id variable. And you're trying to select it. Should be this: $php_errormsg"); // next line has changed $sql = "SELECT * FROM tblArt WHERE IDArt = $your_variable"; $cursor = @odbc_exec($db, $sql) or exit ("Error occrued:$php_errormsg"); odbc_close($db); ?> Tyler Longren Captain Jack Communications [EMAIL PROTECTED] www.captainjack.com - Original Message - From: "Dr. Shim" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, April 01, 2002 10:41 PM Subject: [PHP] Variable Appended To The End of a URL Is Not Working in SQL Query > I have a variable which is appeneded to the end of a URL, like > > http://www.your_web_site.com/your_page/?your_variable=your_value > > This would return "your_value"; > > echo $your_variable; > > But this wouldn't work, and returns an error > > $sql = "SELECT * FROM fldField WHERE IDField = " . $id; > > > What could possibly be wrong? If you need more info, then tell me. Here's my > code: > > $db = @odbc_connect('ReviewDatabase', 'root', '') or exit)("Error > occured:$php_errormsg"); > $sql = "SELECT * FROM tblArt WHERE IDArt = $id"; > $cursor = @odbc_exec($db, $sql) or exit ("Error > occrued:$php_errormsg"); > odbc_close($db); > ?> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable Appended To The End of a URL Is Not Working in SQL Query
Hmm, run it manually? I'm a newbie, so, could you explain how I'd do that? =) "Jason Murray" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... I'd say $id is blank, not being passed in, or is equal to a nonexistant IDArt. Maybe you should echo out your SQL and run it manually to see what's going on. J -- Jason Murray [EMAIL PROTECTED] Web Developer, Melbourne IT "Work now, freak later!" > -Original Message- > From: Dr. Shim [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, April 02, 2002 2:41 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Variable Appended To The End of a URL Is Not Working in > SQL Query > > > I have a variable which is appeneded to the end of a URL, like > > http://www.your_web_site.com/your_page/?your_variable=your_value > > This would return "your_value"; > > echo $your_variable; > > But this wouldn't work, and returns an error > > $sql = "SELECT * FROM fldField WHERE IDField = " . $id; > > > What could possibly be wrong? If you need more info, then > tell me. Here's my > code: > > $db = @odbc_connect('ReviewDatabase', 'root', '') or exit)("Error > occured:$php_errormsg"); > $sql = "SELECT * FROM tblArt WHERE IDArt = $id"; > $cursor = @odbc_exec($db, $sql) or exit ("Error > occrued:$php_errormsg"); > odbc_close($db); > ?> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variable Appended To The End of a URL Is Not Working in SQL Query
I'd say $id is blank, not being passed in, or is equal to a nonexistant IDArt. Maybe you should echo out your SQL and run it manually to see what's going on. J -- Jason Murray [EMAIL PROTECTED] Web Developer, Melbourne IT "Work now, freak later!" > -Original Message- > From: Dr. Shim [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, April 02, 2002 2:41 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Variable Appended To The End of a URL Is Not Working in > SQL Query > > > I have a variable which is appeneded to the end of a URL, like > > http://www.your_web_site.com/your_page/?your_variable=your_value > > This would return "your_value"; > > echo $your_variable; > > But this wouldn't work, and returns an error > > $sql = "SELECT * FROM fldField WHERE IDField = " . $id; > > > What could possibly be wrong? If you need more info, then > tell me. Here's my > code: > > $db = @odbc_connect('ReviewDatabase', 'root', '') or exit)("Error > occured:$php_errormsg"); > $sql = "SELECT * FROM tblArt WHERE IDArt = $id"; > $cursor = @odbc_exec($db, $sql) or exit ("Error > occrued:$php_errormsg"); > odbc_close($db); > ?> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable Appended To The End of a URL Is Not Working in SQL Query
I have a variable which is appeneded to the end of a URL, like http://www.your_web_site.com/your_page/?your_variable=your_value This would return "your_value"; echo $your_variable; But this wouldn't work, and returns an error $sql = "SELECT * FROM fldField WHERE IDField = " . $id; What could possibly be wrong? If you need more info, then tell me. Here's my code: $php_errormsg"); $sql = "SELECT * FROM tblArt WHERE IDArt = $id"; $cursor = @odbc_exec($db, $sql) or exit ("Error occrued:$php_errormsg"); odbc_close($db); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variable problem
On 22 Mar 2002 at 17:27, Rick Emery wrote: > ${varable}ABC in quotes you can help php with {$(varabl)}ABC > > > -Original Message- > From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] > Sent: Friday, March 22, 2002 5:21 PM > To: Rick Emery > Subject: Re: [PHP] Variable problem > > > on 3/22/02 6:18 PM, Rick Emery at [EMAIL PROTECTED] wrote: > > > > show your code > > -Original Message- > From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] > Sent: Friday, March 22, 2002 5:18 PM > To: [EMAIL PROTECTED] > Subject: [PHP] Variable problem > > > I have a variable name in a print <<< END and then some text after it. The > thing is, php thinks that the text is part of the variable name, which makes > the variable, and the text after it, not show up. But, if I put a space, it > makes my html not work right. Any ideas? > > > > > It's something like this: > print <<< END > $varableABC > END; > > > -- ! please check my email address ! ! only my email [EMAIL PROTECTED] works ! ! email [EMAIL PROTECTED] is a black hole since januari 2002 ! Chris Hayes - Droef 35 - Wageningen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Variable problem
${varable}ABC -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] Sent: Friday, March 22, 2002 5:21 PM To: Rick Emery Subject: Re: [PHP] Variable problem on 3/22/02 6:18 PM, Rick Emery at [EMAIL PROTECTED] wrote: show your code -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] Sent: Friday, March 22, 2002 5:18 PM To: [EMAIL PROTECTED] Subject: [PHP] Variable problem I have a variable name in a print <<< END and then some text after it. The thing is, php thinks that the text is part of the variable name, which makes the variable, and the text after it, not show up. But, if I put a space, it makes my html not work right. Any ideas? It's something like this: print <<< END $varableABC END;
RE: [PHP] Variable problem
show your code -Original Message- From: Leif K-Brooks [mailto:[EMAIL PROTECTED]] Sent: Friday, March 22, 2002 5:18 PM To: [EMAIL PROTECTED] Subject: [PHP] Variable problem I have a variable name in a print <<< END and then some text after it. The thing is, php thinks that the text is part of the variable name, which makes the variable, and the text after it, not show up. But, if I put a space, it makes my html not work right. Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable problem
I have a variable name in a print <<< END and then some text after it. The thing is, php thinks that the text is part of the variable name, which makes the variable, and the text after it, not show up. But, if I put a space, it makes my html not work right. Any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable test
> > if($x) >echo $x; if $x is not defined you will get a warning but that depends on error settings in php.ini. This construction checks whether $x is defined or $x is true. > > if(!empty($x)) >echo $x; $x must be defined. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] variable test
Hi, I'm asking me, what is the difference of the two "ifs". if($x) echo $x; if(!empty($x)) echo $x; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable Variables and Mulitdimensional Arrays
Hi. I want to be able to access a key in a multidimensional array at some depth "n" without knowing before runtime what the keys are. I thought this might be possible using variable variables. Here's some sample code using variable variables and multidimensional arrays: $y = 'a'; $z = 'b'; $t = 'c'; $x = array("a"=>array("b"=>array("c"=>TRUE))); print_r($x{$y}{$z}{$t}); // Prints 1. // I want to be able to concatenate the array indexes into one variable variable. This would be done in a loop at runtime. $u = ${$y.$z.$t}; print_r($x{$u}); // Doesn't work. Any help would greatly be appreciated, Charlie -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable scope
Something most have just been wigging out or something because I can't get it to do it again. Maybe I just did something wrong, but it seems to be working now. Thanks for the help though, Dave "Lars Torben Wilson" <[EMAIL PROTECTED]> wrote in message 1015973063.2146.82.camel@ali">news:1015973063.2146.82.camel@ali... > On Tue, 2002-03-12 at 14:38, David Johansen wrote: > > I have a little chunk of code that checks to see if a variable exists and if > > not then it sets it. It goes like this: > > > > if (empty($page)) > > { > >$page = "login"; > > } > > > > I then end that part of the php script after doing what I need to. Then I > > start up again on the same html page and I assumed that $page had a value > > assigned to it because of the above code, but it appears that it doesn't. Is > > this supposed to happen or is something weird happening. I added that little > > bit of code to the second chunk of code and it fixed the problem. Is that > > the "right" way to do it? Is that variable only available in the > > that it's declared in? Thanks, > > Dave > > Shouldn't be. A variable is valid from the point it's declared until > it's unset(), or goes out of scope (the function within which it was > declared ends), or the script ends. > > Can you provide a short script which exhibits this behaviour? > > > -- > Torben Wilson <[EMAIL PROTECTED]> > http://www.thebuttlesschaps.com > http://www.hybrid17.com > http://www.inflatableeye.com > +1.604.709.0506 > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable scope
On Tue, 2002-03-12 at 14:38, David Johansen wrote: > I have a little chunk of code that checks to see if a variable exists and if > not then it sets it. It goes like this: > > if (empty($page)) > { >$page = "login"; > } > > I then end that part of the php script after doing what I need to. Then I > start up again on the same html page and I assumed that $page had a value > assigned to it because of the above code, but it appears that it doesn't. Is > this supposed to happen or is something weird happening. I added that little > bit of code to the second chunk of code and it fixed the problem. Is that > the "right" way to do it? Is that variable only available in the > that it's declared in? Thanks, > Dave Shouldn't be. A variable is valid from the point it's declared until it's unset(), or goes out of scope (the function within which it was declared ends), or the script ends. Can you provide a short script which exhibits this behaviour? -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] variable scope
I have a little chunk of code that checks to see if a variable exists and if not then it sets it. It goes like this: if (empty($page)) { $page = "login"; } I then end that part of the php script after doing what I need to. Then I start up again on the same html page and I assumed that $page had a value assigned to it because of the above code, but it appears that it doesn't. Is this supposed to happen or is something weird happening. I added that little bit of code to the second chunk of code and it fixed the problem. Is that the "right" way to do it? Is that variable only available in the that it's declared in? Thanks, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Variable problem with a function calling a ext. librairy
Hello, I created a librairy with configuration setting: background color, font size, customer's name, etc. Like this: (lib_config.inc) $bgcolor = "#ff"; $co = "ABC enterprise"; A second file is building html page headders: (lib_intra.inc) function title($name_section,$name_page){ print "\n"; print font_titre3."$co\n"; print font_titre2."$name_section\n"; print font_titre2."$name_page\n"; print "\n"; } Finnaly, I call the title function in a web page to dynamicly create the code: (test.php) echo title("General presentation","The annual report"); My problem (you guessed it!) is that the file lib_intra.inc is beeing processed by php (when callled by my web page test.php) and the 2 variables are sent ok but NOT the $co wich is in the 1st file (lib_config.inc). Of course my lib_intra.inc has a: require ("lib_config.inc"); Because I dont want to duplicate infos that are used in many files, the lib_config.inc is important and must be called to supply the data I need. How can I set this so all the variables will be process under php? Thanks to all! -- Marc André Paquin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] how can i pass a javascript variable into a PHP variable?
You can add hidden field in form and before posting set it value to js variable value that can be easily used by PHP script Valentin Petruchek (aki Zliy Pes) *** Cut the beginning *** http://zliypes.com.ua mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] how can i pass a javascript variable into a PHP variable?
Hi, does anyone has an idea and example how to get the value of a js variable into a PHP variable, preferably working with sessionvariables or a hiddenform? thank you! Simon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable problem
I heard before that you can store session variables in a database rather than using the tmp directory etc etc..Does anybody have any links on this? Thanks Randy - Original Message - From: "Yoel Benitez Fonseca" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, January 18, 2002 2:26 PM Subject: RE: [PHP] Variable problem > Use an array !?, I mean : > > $result[$i] = "test"; > > > How do I combine the following so it is treated as one variable > > > > $i=10 > > > > $result$i="test"; > > > > > > I want this to be: > > > > > > $result10="test"; > > > > > > $i changes so I cannot just put in 10 instead of I. > > > > > > anybody know how i can do that? > -- > Yoel Benitez Fonseca > > > > -- > PHP General 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable function call (Re: [PHP] unset a function?)
Hello, > $func = "make_" . $wat; > $temp = $$func($this); I think one $. $func = "make_" . $wat; $temp = $func($this); will work Bas Op donderdag 31 januari 2002 12:17, schreef u: > Hoi Bas, > > $func = "make_" . $wat; > > $temp = $$func($this); > > bvr. > > On Thu, 31 Jan 2002 11:55:12 +0100, Bas Jobsen wrote: > >Hello, > > > >> Thanks all. I will rename the second function. > > > >Now if have: > > > >if($wat=="naam")$temp=make_naam($this); > >else if($wat=="anderenaam")$temp=make_anderenaam($this); > >//etc.. > > > >But i would prefer something like > >$temp=make_$wat($this); > > > >How can i do this? > > > >Tnx, > > > >Bas > > > >-- > >PHP General 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 General 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] variable function call (Re: [PHP] unset a function?)
On Thu, 2002-01-31 at 02:55, Bas Jobsen wrote: > Hello, > > > Thanks all. I will rename the second function. > > Now if have: > > if($wat=="naam")$temp=make_naam($this); > else if($wat=="anderenaam")$temp=make_anderenaam($this); > //etc.. > > But i would prefer something like > $temp=make_$wat($this); > > How can i do this? > > Tnx, > > Bas Use variable function names, like so: Essentially, if you stick an argument list on the end of a variable name, that variable will be evaluated and used as the name of a function to call. Hope this helps, Torben -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General 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] variable function call (Re: [PHP] unset a function?)
Hoi Bas, $func = "make_" . $wat; $temp = $$func($this); bvr. On Thu, 31 Jan 2002 11:55:12 +0100, Bas Jobsen wrote: >Hello, > >> Thanks all. I will rename the second function. > >Now if have: > >if($wat=="naam")$temp=make_naam($this); >else if($wat=="anderenaam")$temp=make_anderenaam($this); >//etc.. > >But i would prefer something like >$temp=make_$wat($this); > >How can i do this? > >Tnx, > >Bas > >-- >PHP General 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 General 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] variable function call (Re: [PHP] unset a function?)
Hey Bas, BV>But i would prefer something like BV>$temp=make_$wat($this); I think you might want something along these lines: eval("make_$wat($this);"); HTH -jeff -- PHP General 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] variable function call (Re: [PHP] unset a function?)
Hello, > Thanks all. I will rename the second function. Now if have: if($wat=="naam")$temp=make_naam($this); else if($wat=="anderenaam")$temp=make_anderenaam($this); //etc.. But i would prefer something like $temp=make_$wat($this); How can i do this? Tnx, Bas -- PHP General 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] Variable referencing/substitution
${$vNames[1]} = "new value"; // look at variable-variables in the manual for more info -Original Message- From: Gaylen Fraley [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 20, 2002 3:44 PM To: [EMAIL PROTECTED] Subject: [PHP] Variable referencing/substitution How can this be done? If I have the name of a variable that is stored in an array, how do I use the stored value to represent the actual variable? Example: $variable = "old value"; $vNames[1] = '$variable'; //literal $variable I want to say $vNames[1] = "new value"; /and have $variable actually change. How? -- Gaylen [EMAIL PROTECTED] Home http://www.gaylenandmargie.com/ PHP KISGB v3.1 Guest Book http://www.gaylenandmargie.com/phpwebsite/ -- PHP General 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] Variable referencing/substitution
How can this be done? If I have the name of a variable that is stored in an array, how do I use the stored value to represent the actual variable? Example: $variable = "old value"; $vNames[1] = '$variable'; //literal $variable I want to say $vNames[1] = "new value"; /and have $variable actually change. How? -- Gaylen [EMAIL PROTECTED] Home http://www.gaylenandmargie.com/ PHP KISGB v3.1 Guest Book http://www.gaylenandmargie.com/phpwebsite/ -- PHP General 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] Variable Problem
Just to add a bit to this thread. The following can be bad: A potential gotcha. Be sure to either define an array key and/or a value. Because assuming all the above are checked, the following will result: $foo = array('on','on','on'); If two are checked, then we'll get: $foo = array('on','on'); Doesn't matter which two were checked :) And as you guessed/know, if no value is set, 'on' will be the value as 'on' is the default value for checkboxes. And, if something is not checked, no value is passed at all. That said, either do one of the following formats, feel free to mix and match, it doesn't matter. Just know what you're doing :) Then work with array foo as you see fit. Be sure to read that faq (link posted earlier), it covers this. Regarding your words, you guessed right, the second wrote over the first. PHP requires [brackets] for arrays in forms. And on a related note, a good way to "debug" arrays is through using print_r or var_dump. You said you use PHP3, so use var_dump(). var_dump($HTTP_POST_VARS); It's been so long since PHP3 was cool, I barely remember how it works. Maybe just try phpinfo() :) But if track_vars are on, predefined php variables such as $HTTP_POST_VARS will exist. And $foo should exist, anyway, enough on that. Try hard to get PHP4 :) http://jp.php.net/manual/ja/language.variables.predefined.php That page is in Japanese, hope it makes sense to you as it sure doesn't to me :) Regards, Philip Olson On Sat, 19 Jan 2002, Steven Maroney wrote: > > I hope im on the right track Cause im jumping in on this post. > > $MYCHK isn't an array cause you aren't using array syntax or simply left > out the brackets. > > try: > > ( for the checkboxes ) > > > > I have done this 100's of times. > > > Hope this helps, > Steve > > On Sat, 19 Jan 2002, K.Tomono wrote: > > > Yes, I think too, it's better way to use an array rather than a dynamic > > name of the variable. > > > > I thought that the first question means how to use a dynamic variable. > > > > By the way, > > > > > little array propaganda, jic :) Arrays work great in forms too! > > > > > > http://www.php.net/manual/en/faq.html.php#AEN73718 > > > > Does this technique work fine on the version 3.0.14 later to 3.0.18 > > of PHP? (Not PHP4) > > > > I tried an array in forms simply like below in the other day, > > but this didn't work fine... > > > > ( for the checkboxes ) > > > > > > > > Unfortunately, I had thought that it could be got as an array, > > but variable $MYCHK is overwritten by the last value "B" always. > > > > (To mention about java servlet, this value could be retrieved by > > the syntax as below. > > > > (HttpServletRequest)request.getParameterValues("MYCHK")[0] > > > > off course, such a syntax occurs an error on PHP. ;D) > > > > -- > > Well, I'll try the technique you mentioned. > > Your offering is very appreciated. > > Thank you! > > :-] > > > > ps. > > execute me for my english... > > > > --- > > K.Tomono > > > > > > > -Original Message- > > > From: Philip Olson [mailto:[EMAIL PROTECTED]] > > > Sent: Saturday, January 19, 2002 2:30 PM > > > To: Fì¤á > > > Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] > > > Subject: Re: [PHP] Variable Problem > > > > > > > > > > > > > How do I combine the following so it is treated as one variable. > > > > > > It's a good question, but why? Most likely an array will > > > work best for > > > this job, arrays are good: > > > > > > http://www.php.net/manual/en/language.types.array.php > > > > > > The man page on foreach is nice too, and has many examples > > > which include > > > while/list alternatives: > > > > > > http://www.php.net/manual/en/control-structures.foreach.php > > > > > > Your question was answered below but I couldn't resist throwing in a > > > little array propaganda, jic :) Arrays work great in forms too! > > > > > > http://www.php.net/manual/en/faq.html.php#AEN73718 > > > > > > Regards, > > > Philip Olson > > > > > > > > > > > > > > > >$i=10 > > > > >$result$i="test"; > > > > >
RE: [PHP] Variable Problem
I hope im on the right track Cause im jumping in on this post. $MYCHK isn't an array cause you aren't using array syntax or simply left out the brackets. try: ( for the checkboxes ) I have done this 100's of times. Hope this helps, Steve On Sat, 19 Jan 2002, K.Tomono wrote: > Yes, I think too, it's better way to use an array rather than a dynamic > name of the variable. > > I thought that the first question means how to use a dynamic variable. > > By the way, > > > little array propaganda, jic :) Arrays work great in forms too! > > > > http://www.php.net/manual/en/faq.html.php#AEN73718 > > Does this technique work fine on the version 3.0.14 later to 3.0.18 > of PHP? (Not PHP4) > > I tried an array in forms simply like below in the other day, > but this didn't work fine... > > ( for the checkboxes ) > > > > Unfortunately, I had thought that it could be got as an array, > but variable $MYCHK is overwritten by the last value "B" always. > > (To mention about java servlet, this value could be retrieved by > the syntax as below. > > (HttpServletRequest)request.getParameterValues("MYCHK")[0] > > off course, such a syntax occurs an error on PHP. ;D) > > -- > Well, I'll try the technique you mentioned. > Your offering is very appreciated. > Thank you! > :-] > > ps. > execute me for my english... > > --- > K.Tomono > > > > -Original Message- > > From: Philip Olson [mailto:[EMAIL PROTECTED]] > > Sent: Saturday, January 19, 2002 2:30 PM > > To: Fì¤á > > Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] > > Subject: Re: [PHP] Variable Problem > > > > > > > > > How do I combine the following so it is treated as one variable. > > > > It's a good question, but why? Most likely an array will > > work best for > > this job, arrays are good: > > > > http://www.php.net/manual/en/language.types.array.php > > > > The man page on foreach is nice too, and has many examples > > which include > > while/list alternatives: > > > > http://www.php.net/manual/en/control-structures.foreach.php > > > > Your question was answered below but I couldn't resist throwing in a > > little array propaganda, jic :) Arrays work great in forms too! > > > > http://www.php.net/manual/en/faq.html.php#AEN73718 > > > > Regards, > > Philip Olson > > > > > > > > > > > >$i=10 > > > >$result$i="test"; > > > > > > > >I want this to be: > > > > > > > >$result10="test"; > > > > > > > >$i changes so I cannot just put in 10 instead of I. > > > >anybody know how i can do that? > > > > > > > >TIA > > > >Randy > > > > > > How about the below. > > > > > > > > $i=10; > > > ${"result$i"}="test"; > > > echo $result10; > > > ?> > > > > > > or > > > > > > > > $i=10; > > > ${'result'.$i}="test"; > > > echo $result10; > > > ?> > > > > > > Cheers :-) > > > --- > > > K.Tomono > > > > > -- > PHP General 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 General 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] Variable Problem
On Saturday 19 January 2002 14:45, K.Tomono wrote: > Yes, I think too, it's better way to use an array rather than a dynamic > name of the variable. > > I thought that the first question means how to use a dynamic variable. > > By the way, > > > little array propaganda, jic :) Arrays work great in forms too! > > > > http://www.php.net/manual/en/faq.html.php#AEN73718 > > Does this technique work fine on the version 3.0.14 later to 3.0.18 > of PHP? (Not PHP4) > > I tried an array in forms simply like below in the other day, > but this didn't work fine... > > ( for the checkboxes ) > > > > Unfortunately, I had thought that it could be got as an array, > but variable $MYCHK is overwritten by the last value "B" always. I don't know whether the following works for PHP3, but for PHP4 you would use: You could even use multi-dimensional arrays: You would reference this as $MYFORM['CHECKBOX']['A'] in your php code. hth -- Jason Wong -> Gremlins Associates -> www.gremlins.com.hk /* If a subordinate asks you a pertinent question, look at him as if he had lost his senses. When he looks down, paraphrase the question back at him. */ -- PHP General 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] Variable Problem
Yes, I think too, it's better way to use an array rather than a dynamic name of the variable. I thought that the first question means how to use a dynamic variable. By the way, > little array propaganda, jic :) Arrays work great in forms too! > > http://www.php.net/manual/en/faq.html.php#AEN73718 Does this technique work fine on the version 3.0.14 later to 3.0.18 of PHP? (Not PHP4) I tried an array in forms simply like below in the other day, but this didn't work fine... ( for the checkboxes ) Unfortunately, I had thought that it could be got as an array, but variable $MYCHK is overwritten by the last value "B" always. (To mention about java servlet, this value could be retrieved by the syntax as below. (HttpServletRequest)request.getParameterValues("MYCHK")[0] off course, such a syntax occurs an error on PHP. ;D) -- Well, I'll try the technique you mentioned. Your offering is very appreciated. Thank you! :-] ps. execute me for my english... --- K.Tomono > -Original Message- > From: Philip Olson [mailto:[EMAIL PROTECTED]] > Sent: Saturday, January 19, 2002 2:30 PM > To: Fì¤á > Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: Re: [PHP] Variable Problem > > > > > How do I combine the following so it is treated as one variable. > > It's a good question, but why? Most likely an array will > work best for > this job, arrays are good: > > http://www.php.net/manual/en/language.types.array.php > > The man page on foreach is nice too, and has many examples > which include > while/list alternatives: > > http://www.php.net/manual/en/control-structures.foreach.php > > Your question was answered below but I couldn't resist throwing in a > little array propaganda, jic :) Arrays work great in forms too! > > http://www.php.net/manual/en/faq.html.php#AEN73718 > > Regards, > Philip Olson > > > > > > > >$i=10 > > >$result$i="test"; > > > > > >I want this to be: > > > > > >$result10="test"; > > > > > >$i changes so I cannot just put in 10 instead of I. > > >anybody know how i can do that? > > > > > >TIA > > >Randy > > > > How about the below. > > > > > $i=10; > > ${"result$i"}="test"; > > echo $result10; > > ?> > > > > or > > > > > $i=10; > > ${'result'.$i}="test"; > > echo $result10; > > ?> > > > > Cheers :-) > > --- > > K.Tomono > -- PHP General 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] Variable Problem
> How do I combine the following so it is treated as one variable. It's a good question, but why? Most likely an array will work best for this job, arrays are good: http://www.php.net/manual/en/language.types.array.php The man page on foreach is nice too, and has many examples which include while/list alternatives: http://www.php.net/manual/en/control-structures.foreach.php Your question was answered below but I couldn't resist throwing in a little array propaganda, jic :) Arrays work great in forms too! http://www.php.net/manual/en/faq.html.php#AEN73718 Regards, Philip Olson > > > >$i=10 > >$result$i="test"; > > > >I want this to be: > > > >$result10="test"; > > > >$i changes so I cannot just put in 10 instead of I. > >anybody know how i can do that? > > > >TIA > >Randy > > How about the below. > > $i=10; > ${"result$i"}="test"; > echo $result10; > ?> > > or > > $i=10; > ${'result'.$i}="test"; > echo $result10; > ?> > > Cheers :-) > --- > K.Tomono -- PHP General 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] Variable Problem
Hello. >How do I combine the following so it is treated as one variable > >$i=10 >$result$i="test"; > >I want this to be: > >$result10="test"; > >$i changes so I cannot just put in 10 instead of I. >anybody know how i can do that? > >TIA >Randy How about the below. or Cheers :-) --- K.Tomono -- PHP General 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] Variable problem
Use an array !?, I mean : $result[$i] = "test"; > How do I combine the following so it is treated as one variable > > $i=10 > > $result$i="test"; > > > I want this to be: > > > $result10="test"; > > > $i changes so I cannot just put in 10 instead of I. > > > anybody know how i can do that? -- Yoel Benitez Fonseca -- PHP General 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] Variable Problem
Valentin Petruchek (aki Zliy Pes) http://zliypes.com.ua mailto:[EMAIL PROTECTED] - Original Message - From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, January 19, 2002 2:47 AM Subject: [PHP] Variable Problem > > > How do I combine the following so it is treated as one variable > > $i=10 > > $result$i="test"; > > > I want this to be: > > > $result10="test"; > > > $i changes so I cannot just put in 10 instead of I. > > > anybody know how i can do that? > > TIA > Randy > > -- > PHP General 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 General 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] Variable Problem
How do I combine the following so it is treated as one variable $i=10 $result$i="test"; I want this to be: $result10="test"; $i changes so I cannot just put in 10 instead of I. anybody know how i can do that? TIA Randy -- PHP General 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] variable variables
On Thu, 17 Jan 2002 11:11:43 -0500, you wrote: >I can not wrap my head around variable variables today, not awake yet or >something. > >For instance I trying something like this: > >while ($i<$loopcounter) { > $temp = "size"; > $valueofsize = $$temp$i; > $i++; >} What about $i = 0; // set the start (or use for()) while ($i<$loopcounter) { > $temp = "size". $i; // $temp = 'size1', 'size2'... $valueofsize = $$temp; $i++; # untested code, should be OK though } No messing around with evals neccessary. Alister -- PHP General 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] variable variables
$valueofsize = ${"size" . $i}; or $var = "size" . $i; $valueofsize = $$var; bvr. On Thu, 17 Jan 2002 11:11:43 -0500, Mike Krisher wrote: >I can not wrap my head around variable variables today, not awake yet or >something. > >For instance I trying something like this: > >while ($i<$loopcounter) { > $temp = "size"; > $valueofsize = $$temp$i; > $i++; >} > >this doesn't work obviously, $valueofsize ends up with a literal value of >"$size1". But I need it to equal the value of a variable named $size1. Do I >need to use a eval() or something? > >Thanks in advance, >¯ Michael Krisher > [EMAIL PROTECTED] > > >-- >PHP General 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 General 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] variable variables
On Thursday, January 17, 2002, at 10:11 AM, Mike Krisher wrote: > I can not wrap my head around variable variables today, not awake yet or > something. > > For instance I trying something like this: > > while ($i<$loopcounter) { > $temp = "size"; > $valueofsize = $$temp$i; > try $valueofsize = ${$temp$i}; > $i++; > } > > this doesn't work obviously, $valueofsize ends up with a literal value > of > "$size1". But I need it to equal the value of a variable named $size1. > Do I > need to use a eval() or something? > > Thanks in advance, > » Michael Krisher > [EMAIL PROTECTED] > > > -- > PHP General 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 General 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] variable variables
there's one example of var-of-vars along with arrays below my rant var-of-var is almost always an evil thing. there are some rare instances where they're necessary, but i assure you that your script would be MUCH cleaner and easier to modify in the future if you used a simple array. compare: $value = $form[$temp . $i]; to: eval('$valueofsize = $'. $temp . $i .';'); $form['size1'] = "hey"; $form['size2'] = "there"; $size1 = "hey"; $size2 = "there"; $loopcounter = 2; while ($i++ < $loopcounter) { $temp = "size"; eval('$valueofsize = $'. $temp . $i .';'); print $valueofsize; print $form[$temp . $i]; } Scott Hurring - Internet Programmer GraphicType Services tel: 973.667.9486 web: http://www.graphictype.com/ pgp: http://graphictype.com/scott/pgp.txt > -Original Message- > From: Mike Krisher [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 17, 2002 11:12 AM > To: [EMAIL PROTECTED] > Subject: [PHP] variable variables > > > I can not wrap my head around variable variables today, not awake yet or > something. > > For instance I trying something like this: > > while ($i<$loopcounter) { > $temp = "size"; > $valueofsize = $$temp$i; > $i++; > } > > this doesn't work obviously, $valueofsize ends up with a literal value of > "$size1". But I need it to equal the value of a variable named $size1. Do I > need to use a eval() or something? > > Thanks in advance, > » Michael Krisher > [EMAIL PROTECTED] > > > -- > PHP General 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 General 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] variable variables
I can not wrap my head around variable variables today, not awake yet or something. For instance I trying something like this: while ($i<$loopcounter) { $temp = "size"; $valueofsize = $$temp$i; $i++; } this doesn't work obviously, $valueofsize ends up with a literal value of "$size1". But I need it to equal the value of a variable named $size1. Do I need to use a eval() or something? Thanks in advance, » Michael Krisher [EMAIL PROTECTED] -- PHP General 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] variable problem - help!
$row[coloumname_${v$ariable}] -Original Message- From: Dani [mailto:[EMAIL PROTECTED]] Sent: Wednesday, January 16, 2002 8:36 AM To: [EMAIL PROTECTED] Subject: [PHP] variable problem - help! Importance: High Hi! I 'm trying not to hard code my php coding and I'm trying to pass a variable name into the $row[coloumname_$variable]; I get an error message for this code. I'm just wondering if I could do this trick using other ways of writing it. Thanks for reviewing! regards, Dani -- PHP General 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 General 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] variable problem - help!
Thanks for the reply! I really appriciate it! I'll try it first! regards, Dani Stefan Rusterholz wrote: > > Hi! > > > > I 'm trying not to hard code my php coding and I'm trying to pass a > > variable name into the $row[coloumname_$variable]; > $row["columname_$variable"] should do it. > $row[constant] is threaten as constant which is normally not the programmers > intention (set_error_reporting(0) and you'll see PHP's complaints about it) > so PHP converts it to $row['constant']. > You may now understand, that PHP "translates" your code to > $row['coloumname_$variable'] whre $variable is a string and not a variable. > > I hope, I could express myself understandable :) > best regards > Stefan Rusterholz -- PHP General 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] variable problem - help!
> Hi! > > I 'm trying not to hard code my php coding and I'm trying to pass a > variable name into the $row[coloumname_$variable]; $row["columname_$variable"] should do it. $row[constant] is threaten as constant which is normally not the programmers intention (set_error_reporting(0) and you'll see PHP's complaints about it) so PHP converts it to $row['constant']. You may now understand, that PHP "translates" your code to $row['coloumname_$variable'] whre $variable is a string and not a variable. I hope, I could express myself understandable :) best regards Stefan Rusterholz -- PHP General 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] variable problem - help!
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 * On 16-01-02 at 12:45 * Dani said > Hi! > > I 'm trying not to hard code my php coding and I'm trying to pass a > variable name into the $row[coloumname_$variable]; > > I get an error message for this code. > > I'm just wondering if I could do this trick using other ways of writing > it. > I'm not sure of the syntax but you need to be looking ar variable variables, there's a whole section on it in the manual. HTH - -- Nick Wilson Tel:+45 3325 0688 Fax:+45 3325 0677 Web:www.explodingnet.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8RWi2HpvrrTa6L5oRAimZAJ4kWwE6Fz9VZgzFZv/1Xl9rfvBZVgCgss/C veKKxbVcUnV493/ykZzoLXw= =G3iP -END PGP SIGNATURE- -- PHP General 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] variable problem - help!
Hi! I 'm trying not to hard code my php coding and I'm trying to pass a variable name into the $row[coloumname_$variable]; I get an error message for this code. I'm just wondering if I could do this trick using other ways of writing it. Thanks for reviewing! regards, Dani -- PHP General 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] printing php variable into html > print $result; ?
A quick rewrite of your code: "; } ?> Your question was how to print the query, in this case you'd just print $sql. That was the point of the above but I got a bit carried away :) Oh, mysql_error() can be very useful for debugging. Regarding the type resource, have a look here: http://www.php.net/manual/en/language.types.resource.php Regards, Philip Olson On Fri, 4 Jan 2002, louie miranda wrote: > Hi, is it possible to print the sql query? i mean > i want to print the output of the command "SELECT * FROM members;" > and output it into html, i tried > > print $result; -- it gives me different output.. > > > Resource id #2 > > > ty, > louie... > > # PHP SCRIPT ### > > > > > > $db = mysql_connect("my_db_host", "my_db_user", "my_db_pass") > or die("Could not connect"); > > mysql_select_db("cavite",$db); > > $result = mysql_query("SELECT * FROM members",$db) or > die("Error:".mysql_error() > ); > > printf("ircname: %s", mysql_result($result,0,"ircname")); > printf("email: %s", mysql_result($result,0,"email")); > printf("realname: %s", mysql_result($result,0,"realname")); > printf("asl: %s", mysql_result($result,0,"asl")); > printf("info: %s", mysql_result($result,0,"info")); > > print ""; > > ?> > > > > > > # PHP SCRIPT ### > > > -- > PHP General 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 General 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] printing php variable into html > print $result; ?
something like someColumnInTable; echo $row->someOtherColumnInTable; } ?> -- Original Message -- From: "louie miranda" <[EMAIL PROTECTED]> Date: Fri, 4 Jan 2002 04:45:57 +0800 Hi, is it possible to print the sql query? i mean i want to print the output of the command "SELECT * FROM members;" and output it into html, i tried print $result; -- it gives me different output.. > Resource id #2 ty, louie... # PHP SCRIPT ### ", mysql_result($result,0,"ircname")); printf("email: %s", mysql_result($result,0,"email")); printf("realname: %s", mysql_result($result,0,"realname")); printf("asl: %s", mysql_result($result,0,"asl")); printf("info: %s", mysql_result($result,0,"info")); print ""; ?> # PHP SCRIPT ### -- PHP General 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] -- Charles Killmer Netgain Technology 251-4700 -- -- PHP General 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] printing php variable into html > print $result; ?
use $sql = "select .. "; $result = mysql_query($sql); echo $sql; --- louie miranda <[EMAIL PROTECTED]> wrote: > Hi, is it possible to print the sql query? i mean > i want to print the output of the command "SELECT * FROM > members;" > and output it into html, i tried > > print $result; -- it gives me different output.. > > > Resource id #2 > > > ty, > louie... > > # PHP SCRIPT > ### > > > > > > $db = mysql_connect("my_db_host", "my_db_user", > "my_db_pass") > or die("Could not connect"); > > mysql_select_db("cavite",$db); > > $result = mysql_query("SELECT * FROM members",$db) or > die("Error:".mysql_error() > ); > > printf("ircname: %s", > mysql_result($result,0,"ircname")); > printf("email: %s", mysql_result($result,0,"email")); > printf("realname: %s", > mysql_result($result,0,"realname")); > printf("asl: %s", mysql_result($result,0,"asl")); > printf("info: %s", mysql_result($result,0,"info")); > > print ""; > > ?> > > > > > > # PHP SCRIPT > ### > > > -- > PHP General 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] > = Mehmet Erisen http://www.erisen.com __ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- PHP General 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] printing php variable into html > print $result; ?
Hi, is it possible to print the sql query? i mean i want to print the output of the command "SELECT * FROM members;" and output it into html, i tried print $result; -- it gives me different output.. > Resource id #2 ty, louie... # PHP SCRIPT ### ", mysql_result($result,0,"ircname")); printf("email: %s", mysql_result($result,0,"email")); printf("realname: %s", mysql_result($result,0,"realname")); printf("asl: %s", mysql_result($result,0,"asl")); printf("info: %s", mysql_result($result,0,"info")); print ""; ?> # PHP SCRIPT ### -- PHP General 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] Variable Swap?
Try this (I only tested it shortly if it works with scalars, but it should also with arrays): #swap $a, $b list($a, $b) = array($b, $a); Stefan Rusterholz, [EMAIL PROTECTED] -- interaktion gmbh Stefan Rusterholz Zürichbergstrasse 17 8032 Zürich -- T. +41 1 253 19 55 F. +41 1 253 19 56 W3 www.interaktion.ch -- - Original Message - From: "Bharath Bhushan Lohray" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Sunday, December 09, 2001 1:24 PM Subject: [PHP] Variable Swap? > Is there a way of swapping the values of two variables without involving a > third variable. > > something similar to the SWAP(A$,B$) of BASIC > > I have a big variable(array) and I want to keep my script's memory > requirements as low as possible. > > -Bharath Bhushan Lohray > > > > -- > PHP General 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 General 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] Variable Swap?
Is there a way of swapping the values of two variables without involving a third variable. something similar to the SWAP(A$,B$) of BASIC I have a big variable(array) and I want to keep my script's memory requirements as low as possible. -Bharath Bhushan Lohray -- PHP General 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] variable scope / preg_replace_callback question
function _compile_lang($key){ global $_lang; return $_lang[$key[1]]; } // End _compile_lang HTH Regards, Andrey Hristov - Original Message - From: "Peter Bowyer" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, December 03, 2001 3:45 PM Subject: [PHP] variable scope / preg_replace_callback question > Hi, > > Does anyone know of a way of passing other variables to the function being called by >preg_replace_callback? For instance, I have the following code: > > function smarty_compile_lang($tpl_source) { > // en.php contains a very large array, $_lang > include_once '/home/test/en.php'; > global $_lang; > return preg_replace_callback('/##(.+?)##/', '_compile_lang', $tpl_source); > } > > function _compile_lang($key){ > // If I include $_lang here then it gets > // loaded again and again - bad for performance as it is _very_ large > return $_lang[$key[1]]; > } // End _compile_lang > > Somehow I need to make $_lang global, or pass it through the function >preg_replace_callback as an arguement for _compile_lang() - which I don't think is possible? > > What can I do? I've tried a global statement everywhere I can think of... and I >don't want to include en.php outside the functions, as it'll be included then whether the templates are being compiled or not. I'm > guessing that I may want to look at a higher level of abstraction from these >functions, as even if I have the include in the current place, it means that every time a template is compiled it gets reloaded (though that's > not as bad as every time preg_replace_callback() finds something) whereas the best >way would be to load it once per script invocation - and then only when the templates wer being compiled... > > Suggestions? > > TIA, > Peter. > > > > -- > PHP General 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 General 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] variable scope / preg_replace_callback question
Hi, Does anyone know of a way of passing other variables to the function being called by preg_replace_callback? For instance, I have the following code: function smarty_compile_lang($tpl_source) { // en.php contains a very large array, $_lang include_once '/home/test/en.php'; global $_lang; return preg_replace_callback('/##(.+?)##/', '_compile_lang', $tpl_source); } function _compile_lang($key){ // If I include $_lang here then it gets // loaded again and again - bad for performance as it is _very_ large return $_lang[$key[1]]; } // End _compile_lang Somehow I need to make $_lang global, or pass it through the function preg_replace_callback as an arguement for _compile_lang() - which I don't think is possible? What can I do? I've tried a global statement everywhere I can think of... and I don't want to include en.php outside the functions, as it'll be included then whether the templates are being compiled or not. I'm guessing that I may want to look at a higher level of abstraction from these functions, as even if I have the include in the current place, it means that every time a template is compiled it gets reloaded (though that's not as bad as every time preg_replace_callback() finds something) whereas the best way would be to load it once per script invocation - and then only when the templates wer being compiled... Suggestions? TIA, Peter. -- PHP General 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] Re: How to get mysql-result into a php variable
I'm not sure where you found the function mysql_store_result, but it is not a built-in PHP function and that is why you are getting an error. If you just want to return Match if one or more rows in the group match the first name use something like this: function LookupFirstname ($FName, $Group, $Conn) { $SQL = "SELECT ."; $Result = mysql_query($SQL,$Conn) or die (mysql_error()); if (mysql_num_rows($Result) > 0) { $Match = "Match"; } else {$Match = "NoMatch";} return $Match; } Olav Drageset <[EMAIL PROTECTED]> wrote in message 1104_1006021222@alfa">news:1104_1006021222@alfa... > This is perhaps elementary, but I cannot find solution in the documentation > > I want to transfer to a php variable wheter I find a matching firstname in a group from mysql db > > function lookupFirstname ($fname, $gr, $conection) > { $sql = "SELECT firstname AS matches "; > $sql .= "FROM persons "; > $sql .= "WHERE firstname = '$fname' AND group='$gr';"; > > if (!$sql_result = mysql_query($sql,$connection) ) > {echo "query: "; echo mysql_error(); } > > $store = mysql_store_result($conn); > $result = mysql_num_rows($store); > > IF ($result > 0) {return 'match' ;} ELSE {return 'nomatch';} > } > > I get error message that funcion mysql_stor_result() is not defined > How shall I use thees two funcions? > > Thank you > Olav > -- PHP General 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] How to get mysql-result into a php variable
This is perhaps elementary, but I cannot find solution in the documentation I want to transfer to a php variable wheter I find a matching firstname in a group from mysql db function lookupFirstname ($fname, $gr, $conection) { $sql = "SELECT firstname AS matches "; $sql .= "FROM persons "; $sql .= "WHERE firstname = '$fname' AND group='$gr';"; if (!$sql_result = mysql_query($sql,$connection) ) {echo "query: "; echo mysql_error(); } $store = mysql_store_result($conn); $result = mysql_num_rows($store); IF ($result > 0) {return 'match' ;} ELSE {return 'nomatch';} } I get error message that funcion mysql_stor_result() is not defined How shall I use thees two funcions? Thank you Olav -- PHP General 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] Variable definitions...
BTW, the official explanation is wrong. "local part this variable is destroyed and declared again" is incorrect. The global variable is not destroyed. The local namespace pushes the variable name onto the stack and gives it a value for the duration of the function. Every time you try and access this variable it is taken from the stack by the parser. Once you exit the function the local namespace is destroyed and all the local variables are popped from the stack. If the call stack is in the Global area then all variabels are accessed from the heap, so your original variable (and its original value) are still accessible. > -Original Message- > From: Chris Hobbs [mailto:[EMAIL PROTECTED]] > Sent: 13 November 2001 17:09 > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: Re: [PHP] Variable definitions... > > > Hi Stephan, > > IMHO, I think the answer requested is the only one that really makes > sense - as soon as I read it, _my_ first thought went to scope. > > If a variable changes values, the other value is no longer usable, and > thus there aren't really two variables with the same name in that case. > When comparing global to local scope, however, you can definitely have > the same name in use in two places. > > Of course, I wasn't a CS major, so someone else might be able to give > you an answer that will help you justify yours - but prima facie, you > got it wrong :( > > Now, if you're talking about the compiler level, then no two variables > (which are actually memory registers at this point, iirc) can share the > same memory space with different values - this is just logically > impossible. But the question is certainly referring to source code, and > so scope is the only reasonable answer. > > HTH! > > Stephan wrote: > > > Hello, > > > > first of all I didn't exactely know where the right place is to ask this > > question. > > > > Well, my problem is that I just had some exams and am very unhappy on > > how certain things were rated. > > > > There's especially one question and I try to translate it as exact as > > possible: > > > > When is it possible that two variables have the same name but display > > different variables? > > > > The official solution was when in a script a global variable is declared > > and then in a local part this variable is destroyed and declared again > > with the same name (maybe even using different data type). > > > > As for me, I'm of the opinion that this definition according to the > > question is too narrow minded. I think that a variable is already > > different if the the value within the variable is changed due to script > > OR if you appoint a new value to the variable OR if the variable is an > > array and some elements are accessed / elements are added / elements are > > removed. > > The reason why I think variables with different values can be considered > > as different variable according to the question asked in the exam is > > that when you declare a variable it also has a value even if this value > > is NULL. > > > > Now I'd like very much to hear your opinion on this issue since for me > > very much depends on that (3 years of studying at college). > > > > Stephan > > > > P.S.: If you agree with me or not can you also send me an email to me? > > [EMAIL PROTECTED] > > > > > > > > > -- > ___ ____ _ > Chris Hobbs / \ \/ / | | |/ ___\| __ \ > Head Geek| (___ \ \ / /| | | | (___ | | | | > WebMaster \___ \ \ \/ / | | | |\___ \| | | | > PostMaster) | \ / | |__| |) | |__| | >\/\/\/ \/|_/ >http://www.silvervalley.k12.ca.us >[EMAIL PROTECTED] > > > -- > PHP General 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 General 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] Variable definitions...
Hi Stephan, IMHO, I think the answer requested is the only one that really makes sense - as soon as I read it, _my_ first thought went to scope. If a variable changes values, the other value is no longer usable, and thus there aren't really two variables with the same name in that case. When comparing global to local scope, however, you can definitely have the same name in use in two places. Of course, I wasn't a CS major, so someone else might be able to give you an answer that will help you justify yours - but prima facie, you got it wrong :( Now, if you're talking about the compiler level, then no two variables (which are actually memory registers at this point, iirc) can share the same memory space with different values - this is just logically impossible. But the question is certainly referring to source code, and so scope is the only reasonable answer. HTH! Stephan wrote: > Hello, > > first of all I didn't exactely know where the right place is to ask this > question. > > Well, my problem is that I just had some exams and am very unhappy on > how certain things were rated. > > There's especially one question and I try to translate it as exact as > possible: > > When is it possible that two variables have the same name but display > different variables? > > The official solution was when in a script a global variable is declared > and then in a local part this variable is destroyed and declared again > with the same name (maybe even using different data type). > > As for me, I'm of the opinion that this definition according to the > question is too narrow minded. I think that a variable is already > different if the the value within the variable is changed due to script > OR if you appoint a new value to the variable OR if the variable is an > array and some elements are accessed / elements are added / elements are > removed. > The reason why I think variables with different values can be considered > as different variable according to the question asked in the exam is > that when you declare a variable it also has a value even if this value > is NULL. > > Now I'd like very much to hear your opinion on this issue since for me > very much depends on that (3 years of studying at college). > > Stephan > > P.S.: If you agree with me or not can you also send me an email to me? > [EMAIL PROTECTED] > > > -- ___ ____ _ Chris Hobbs / \ \/ / | | |/ ___\| __ \ Head Geek| (___ \ \ / /| | | | (___ | | | | WebMaster \___ \ \ \/ / | | | |\___ \| | | | PostMaster) | \ / | |__| |) | |__| | \/\/\/ \/|_/ http://www.silvervalley.k12.ca.us [EMAIL PROTECTED] -- PHP General 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] Variable definitions...
Hello, first of all I didn't exactely know where the right place is to ask this question. Well, my problem is that I just had some exams and am very unhappy on how certain things were rated. There's especially one question and I try to translate it as exact as possible: When is it possible that two variables have the same name but display different variables? The official solution was when in a script a global variable is declared and then in a local part this variable is destroyed and declared again with the same name (maybe even using different data type). As for me, I'm of the opinion that this definition according to the question is too narrow minded. I think that a variable is already different if the the value within the variable is changed due to script OR if you appoint a new value to the variable OR if the variable is an array and some elements are accessed / elements are added / elements are removed. The reason why I think variables with different values can be considered as different variable according to the question asked in the exam is that when you declare a variable it also has a value even if this value is NULL. Now I'd like very much to hear your opinion on this issue since for me very much depends on that (3 years of studying at college). Stephan P.S.: If you agree with me or not can you also send me an email to me? [EMAIL PROTECTED] -- PHP General 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] variable issue
thanks for all the help. I realized that I did not need the else, and the isset() works great! Now I have my calendar working the way I want it to! Thanks! Clint -- Original Message -- From: "Matthew Luchak" <[EMAIL PROTECTED]> Date: Fri, 9 Nov 2001 15:07:22 -0500 if(!isset($dte)) { $dte=date("j", time()+$ctime);} You don't need the else statement. Matthew Luchak Webmaster Kaydara Inc. [EMAIL PROTECTED] -Original Message- From: Clint Tredway [mailto:[EMAIL PROTECTED]] Sent: Friday, November 09, 2001 2:37 PM To: PHP General Subject: [PHP] variable issue Hey everyone, I need some help with a variable issue. How can I delcare a variable and then if a url variable of the same name is present use that value instead? this is what I have: if(!$dte) { $dte=date("j", time()+$ctime); } else { $dte=$dte; } and this causing an error in the 'if' expression. Thanks! clint -- PHP General 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 General 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 General 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] variable issue
if(!isset($dte)) { $dte=date("j", time()+$ctime);} You don't need the else statement. Matthew Luchak Webmaster Kaydara Inc. [EMAIL PROTECTED] -Original Message- From: Clint Tredway [mailto:[EMAIL PROTECTED]] Sent: Friday, November 09, 2001 2:37 PM To: PHP General Subject: [PHP] variable issue Hey everyone, I need some help with a variable issue. How can I delcare a variable and then if a url variable of the same name is present use that value instead? this is what I have: if(!$dte) { $dte=date("j", time()+$ctime); } else { $dte=$dte; } and this causing an error in the 'if' expression. Thanks! clint -- PHP General 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 General 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] variable issue
replace the if statement if(!$dte) with if (!isset($dte)) - Original Message - From: "Johnson, Kirk" <[EMAIL PROTECTED]> To: "PHP General" <[EMAIL PROTECTED]> Sent: Friday, November 09, 2001 2:35 PM Subject: RE: [PHP] variable issue > The else clause can be removed, since it is not doing anything. What is the > error message? > > Kirk > > > Hey everyone, I need some help with a variable issue. How can > > I delcare a variable and then if a url variable of the same > > name is present use that value instead? > > > > this is what I have: > > if(!$dte) > > { > > $dte=date("j", time()+$ctime); > > } > > else > > { > > $dte=$dte; > > } > > and this causing an error in the 'if' expression. > > -- > PHP General 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 General 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] variable issue
The else clause can be removed, since it is not doing anything. What is the error message? Kirk > Hey everyone, I need some help with a variable issue. How can > I delcare a variable and then if a url variable of the same > name is present use that value instead? > > this is what I have: > if(!$dte) > { > $dte=date("j", time()+$ctime); > } > else > { > $dte=$dte; > } > and this causing an error in the 'if' expression. -- PHP General 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] variable issue
Hey everyone, I need some help with a variable issue. How can I delcare a variable and then if a url variable of the same name is present use that value instead? this is what I have: if(!$dte) { $dte=date("j", time()+$ctime); } else { $dte=$dte; } and this causing an error in the 'if' expression. Thanks! clint -- PHP General 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] variable gets lost in function problem again...
> I have an two dimensional array that is returned from code from an included > file. I'm assigning parts of the array to variables ( $variable = > $array["key"]["value"]; ). This works fine and can be printed until I send > it through a function eg. ( ereg_replace(" ", "_", "$variable"); ). After > this, $variable is blank. > > I don't think it's my code because substituting a text string for the array > data (eg. $variable = "this is some text";) works just fine. > > It has something to do with the assigning array data to a variable or > perhaps that the data comes from an included file... This could be a bug in > PHP? Spunk Could you post some excerpted code please? You seem to have multiple issues: 1 communication between a 'mainline' and INCLUDEd code 2 communication between a 'mainline' and a function 3 working with scalars and arrays 4 working with text strings and ?text arrays - which may or may not be related/relevant Let's start with simple ideas: 0 put debug echo statements into the function (or everywhere) to track progress 1 if you take the processing code out of the INCLUDE file and put it in the 'mainline', does it then work as planned? 2 do you have an & to indicate a pass by reference cf a pass by value (see manual)? 3 and 4 does the processing use tools/approach/functions that only work with scalars/arrays/strings? A process of elimination... Keep us posted, =dn -- PHP General 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] variable gets lost in function problem again...
Sorry all but I really need to figure this out. Here's a recap of my problem: I have an two dimensional array that is returned from code from an included file. I'm assigning parts of the array to variables ( $variable = $array["key"]["value"]; ). This works fine and can be printed until I send it through a function eg. ( ereg_replace(" ", "_", "$variable"); ). After this, $variable is blank. I don't think it's my code because substituting a text string for the array data (eg. $variable = "this is some text";) works just fine. It has something to do with the assigning array data to a variable or perhaps that the data comes from an included file... This could be a bug in PHP? Does this sound familiar to anybody? I can't figure it out! Any help would be much appreciated. Thanks, Spunk -- PHP General 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] variable operators in queries
Hello, Is it possible to put variable operators in queries? I tried this (the real variable comes from a form) $Date_Operator =(">="); sql="SELECT * FROM poeple WHERE age $Date_operator 20"; $result_id = mysql_query($sql); It doesn't work like this. I also tried: sql="SELECT * FROM poeple WHERE age \"$Date_operator\" 20" $result_id = mysql_query($sql); it didn't work either. Or should I use a have to make a IF-Then construction? If $Date_Operator == (">=") then { sql="SELECT * FROM poeple WHERE age >= 20" } etc... Can anybody help me with this? Thanks in advance! -- Met vriendelijke groet / With Greetings, Sander Peters site: http://www.visionnet.nl/ email: mailto:[EMAIL PROTECTED] webmail: mailto:[EMAIL PROTECTED] -- PHP General 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] Variable & Configuration Problem
Hello all! I installed PHP 4.0.6 om my server (Winnt server, Apache), and I started testing with it. The problem I have now is this: I want to read the data passed from a form trough a variable. Let's say the form field is called Test. I want to use $Test in my PHP script to read that variable. But all variables stay empty. I don't wan't to use the Query_string to get my variables. Can anybody tell me what INI-setting(s) I got to turn on or off?? Thanks!!! Greetz Patrick -- PHP General 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] Variable declaration
> > its really a big headache with compilers like c bugging all the way just for >declarations. One remark, btw. Using explicit declarations isn't really more of a headache then _not_ using expl.decl. When you don't use explicit declarations, you'll need to check wether or not a variable is defined at (almost) any point where you want to use it. But... like I said; it's more a matter of preference. Only thing is that when I look at quite a lot of people who post on this mailinglist, I think it shouldn't be such a bad idea to force them into coding a bit stricter. Many people just start using variables "because they'll probably already been defined". That's not something you can depend on. Same with people who think they can just use variables that have been posted from a form. No need to check them for being defined?!? I think you should. You cannot depend on user-inputs. And there's always a possibility of people bookmarking specific pages or typing URL's themselves. You'll always need to check variable before you use them. Explicit declaration at least address a part of this problem. It forced people to code a bit stricter. -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- PHP General 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] Variable declaration
From: sagar N Chand <[EMAIL PROTECTED]> Date: Thu, Sep 27, 2001 at 06:01:26PM +0530 Message-ID: <005101c14750$c3189b10$0101a8c0@inferno> Subject: Re: [PHP] Variable declaration > its really a big headache with compilers like c bugging all the way just for >declarations. > its cl to have the freedom of using any variable at any place wherever v want in >bet > ween the code. chao of PHP. > > /sagar I think it's just a matter of preference. I like this, you like that. No harm to that. That's why I proposed the E_EXPLICIT_DECLARATION. That way I can choose to use it, and you can leave it for what it is. Kinda like what Perl does with "use strict;". If you don't like being forced to declare every variable before you use it, you just don't type "use strict;" at the start of your script. People like me, who do like to do that, _do_ use that option. Everyone gets it his/her way and it bothers noone. But anyway... I don't think they'll ever implement this, so (...) NOTE: PHP Rulz and this is just a small thing that doesn't change anything to the superb power of PHP webbuilding! :) -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- PHP General 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] Variable declaration
its really a big headache with compilers like c bugging all the way just for declarations. its cl to have the freedom of using any variable at any place wherever v want in bet ween the code. chao of PHP. /sagar - Original Message - From: * R&zE: To: Rasmus Lerdorf Cc: [EMAIL PROTECTED] Sent: Thursday, September 27, 2001 2:02 PM Subject: Re: [PHP] Variable declaration > That is the nature of a loosely typed scripting language. I know. > If you prefer a strongly typed compiled language, there are plenty > of those available. I know to. But those are not as powerful for building websites as PHP. I mean... don't get me wrong here, I think PHP is great (or even better). It's terrific actually. I just wish sometimes that the compiler wouldn't allow so many things. It might just be a bit more strict. Or at least a seperate option for being more strict. Eg something like E_EXPLICIT_DECLARE ;) -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- PHP General 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] Variable declaration
> That is the nature of a loosely typed scripting language. I know. > If you prefer a strongly typed compiled language, there are plenty > of those available. I know to. But those are not as powerful for building websites as PHP. I mean... don't get me wrong here, I think PHP is great (or even better). It's terrific actually. I just wish sometimes that the compiler wouldn't allow so many things. It might just be a bit more strict. Or at least a seperate option for being more strict. Eg something like E_EXPLICIT_DECLARE ;) -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- PHP General 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] Variable declaration
That is the nature of a loosely typed scripting language. If you prefer a strongly typed compiled language, there are plenty of those available. -Rasmus On Thu, 27 Sep 2001, * R&zE: wrote: > > Like I said, that line does both. It sets the type internally to an > > integer and assigns the value. > > > > -Rasmus > > What he (Alberto) is looking for, and what I would prefer to, is to > really explicitly declare a variable. There's a difference between a > compiler that requires you to declare (integer $Test;) a variable > _before_ you start using it ($Test = 3;). Ofcourse I know that PHP > internally declares it, but it's not the same thing. > > When the compiler forces you to declare all variables you're gonna > use it gives a better view of which variables are used in the > script, and besides that it doesn't allow you to make any mistakes > of using undefined variables like it does now. > > The PHP compiler doesn't really check your code intensively. You can > use any variable without the compiler complaining. Only at the > moment that it reaches the variable and finds out it isn't defined, > it tells you. It would be better to explicitly have to declare the > variable. When the compiler starts it then shouldn't execute the > code when it contains any variable that is not explicitly declared. > > But like I said, FAFAIK explicitly declaring variables isn't > supported by PHP :( > > -- PHP General 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] Variable declaration
> Like I said, that line does both. It sets the type internally to an > integer and assigns the value. > > -Rasmus What he (Alberto) is looking for, and what I would prefer to, is to really explicitly declare a variable. There's a difference between a compiler that requires you to declare (integer $Test;) a variable _before_ you start using it ($Test = 3;). Ofcourse I know that PHP internally declares it, but it's not the same thing. When the compiler forces you to declare all variables you're gonna use it gives a better view of which variables are used in the script, and besides that it doesn't allow you to make any mistakes of using undefined variables like it does now. The PHP compiler doesn't really check your code intensively. You can use any variable without the compiler complaining. Only at the moment that it reaches the variable and finds out it isn't defined, it tells you. It would be better to explicitly have to declare the variable. When the compiler starts it then shouldn't execute the code when it contains any variable that is not explicitly declared. But like I said, FAFAIK explicitly declaring variables isn't supported by PHP :( -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- PHP General 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] Variable declaration
> > What do you mean force declaration? That's what you are doing with this > > line: > > > > $Test = 3; > > Nop! This is just starting to use a variable. Something like: > >integer $Test; > > is declaring a variable. But FAFAIK it's not possible in PHP :( Like I said, that line does both. It sets the type internally to an integer and assigns the value. -Rasmus -- PHP General 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] Variable declaration
> What do you mean force declaration? That's what you are doing with this > line: > > $Test = 3; Nop! This is just starting to use a variable. Something like: integer $Test; is declaring a variable. But FAFAIK it's not possible in PHP :( -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- PHP General 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] Variable declaration
On Thu, 27 Sep 2001, it was written: > $Test=3; > echo $Test; > ?> > > And I get no warning about $Test not being declared before (like C > declaration). > > Any1 has an example about forcing variable declaration? What do you mean force declaration? That's what you are doing with this line: $Test = 3; This declares $Test to be an integer with the value 3. Assignment and declaration is done in one step. There is no mechanism to do it in two. -Rasmus -- PHP General 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] Variable declaration
And I get no warning about $Test not being declared before (like C declaration). Any1 has an example about forcing variable declaration? -- PHP General 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] Variable variables
If I'm reading your snippet correctly, then : $foo = 'bar'; $bar = array('apple','banana'); print ${$foo}[0]; // apple Note the use of {braces}. The last paragraph in the manual describes this a bit : http://www.php.net/manual/en/language.variables.variable.php Although I don't see the point of $newvar as you're keeping track of $a in the array itself. Looks like the below code will create a ton of variables (arrays) each with one $a as the single key. Just using $finalresult may be more appropriate, hard to say. And some tips : $arr[foo] will create an error/warning here, $arr['foo'] will not. "$foo" isn't as pretty as $foo regards, Philip Olson On Wed, 26 Sep 2001, Richard Baskett wrote: > I can not figure out why this is not working! > > for ($j=0; $j<$resultNum; $j++) { > $newvar = "finalresult".$a; > $$newvar[$a][name] = $resultRow[name]; > $$newvar[$a][title]= $resultRow[title]; > $$newvar[$a][descript] = $resultRow[descript]; > $$newvar[$a][countkey] = substr_count("$resultRow[keywords]", "$keyword"); > a++; > } > > This is how you use variable variables, is it not? Is it because it's a > multidimensional array? or am I missing something else? > > Rick > > > -- > PHP General 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 General 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] Variable variables
I can not figure out why this is not working! for ($j=0; $j<$resultNum; $j++) { $newvar = "finalresult".$a; $$newvar[$a][name] = $resultRow[name]; $$newvar[$a][title]= $resultRow[title]; $$newvar[$a][descript] = $resultRow[descript]; $$newvar[$a][countkey] = substr_count("$resultRow[keywords]", "$keyword"); a++; } This is how you use variable variables, is it not? Is it because it's a multidimensional array? or am I missing something else? Rick -- PHP General 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] Variable declaration
> I want PHP parser to warn/fail when I try to use a variable > not declared before. Like "Option Explicit" on ASP/VBA. Look here: http://www.php.net/manual/en/function.error-reporting.php Chris
[PHP] Variable declaration
I want PHP parser to warn/fail when I try to use a variable not declared before. Like "Option Explicit" on ASP/VBA. Thnx in advance :) -- PHP General 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] Variable naming
That was the ticket. Thanks a lot for your help Adam Plocher wrote: > $id = 1; > ${"sql_" . $id} = "hey"; > print $sql_1; -- Kyle Moore UNIX Systems Administrator Trust Company of America -- PHP General 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] Variable naming
Read this http://www.php.net/manual/en/language.variables.variable.php Johan www.pongworld.com php tt -Original Message- From: Fábio Migliorini [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 25, 2001 12:28 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Variable naming $id = 1; $sql_1 = "hey"; $vname = "sql_".$id; echo $$vname; -- Fábio Migliorini http://www.atua.com.br [EMAIL PROTECTED] UIN: 42729458 Linux User: 175409 - Original Message - From: "Kyle Moore" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, September 25, 2001 1:15 PM Subject: [PHP] Variable naming > I want to use the value of a variable in a variable name. For instance: > > $id = 1; > $sql_$id = "hey"; //set variable $sql_1 to hey > print $sql_1; //should print hey > > I have looked high and low on how to do this. My first idea was eval but > I can't seem to get that to work in this instance. Any ideas? I'm sure > it is possible and easy but I just can't figure out how to do this in > php. > > Thanks > > -- > Kyle > > > -- > PHP General 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 General 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 General 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] Variable naming
$id = 1; $sql_1 = "hey"; $vname = "sql_".$id; echo $$vname; -- Fábio Migliorini http://www.atua.com.br [EMAIL PROTECTED] UIN: 42729458 Linux User: 175409 - Original Message - From: "Kyle Moore" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, September 25, 2001 1:15 PM Subject: [PHP] Variable naming > I want to use the value of a variable in a variable name. For instance: > > $id = 1; > $sql_$id = "hey"; //set variable $sql_1 to hey > print $sql_1; //should print hey > > I have looked high and low on how to do this. My first idea was eval but > I can't seem to get that to work in this instance. Any ideas? I'm sure > it is possible and easy but I just can't figure out how to do this in > php. > > Thanks > > -- > Kyle > > > -- > PHP General 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 General 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] Variable naming
$id = 1; ${"sql_" . $id} = "hey"; print $sql_1; Try that -Original Message- From: Kyle Moore [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 25, 2001 9:15 AM To: [EMAIL PROTECTED] Subject: [PHP] Variable naming I want to use the value of a variable in a variable name. For instance: $id = 1; $sql_$id = "hey"; //set variable $sql_1 to hey print $sql_1; //should print hey I have looked high and low on how to do this. My first idea was eval but I can't seem to get that to work in this instance. Any ideas? I'm sure it is possible and easy but I just can't figure out how to do this in php. Thanks -- Kyle -- PHP General 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] Variable naming
> I want to use the value of a variable in a variable name. For > instance: > > $id = 1; > $sql_$id = "hey"; //set variable $sql_1 to hey > print $sql_1; //should print hey I *believe* (could be wrong) what you want is this: print ${$sql_1}; Check out variable variables in the dox. Chris
[PHP] Variable naming
I want to use the value of a variable in a variable name. For instance: $id = 1; $sql_$id = "hey"; //set variable $sql_1 to hey print $sql_1; //should print hey I have looked high and low on how to do this. My first idea was eval but I can't seem to get that to work in this instance. Any ideas? I'm sure it is possible and easy but I just can't figure out how to do this in php. Thanks -- Kyle -- PHP General 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] Variable conversion problem
On Friday 21 September 2001 01:45, Neil Silvester wrote: > Another PHP problem has kept me up all night, scouring through my database > books and trying everything I could think of. I am still new to the MySQL > and PHP field, but never the lass I will not give up. > $cat is a variable that is passed to the query from the previous page. The > SELECT statement works faultlessly, except for the point at which no choice > is made from the drop down on the page prior to this one. I have set a > value > > of "x" to the drop down for a non selection, but am having problems > converting that "x" value to a "%" value (the MySql wildcard symbol) > withing my SELECT statement. > I am assuming that I will need an IF THEN before the SELECT, but I have > tried several variation to no avail. > > $result = mysql_query("SELECT CompetitorName > FROM competitor, competitorproducts, productcategory > WHERE competitorproducts.CompID=competitor.ID > AND productcategory.ID=\"$cat\" > AND competitorproducts.CatID=productcategory.ID" > ); I'd say there are 2 solutions: 1) Set the default value in the dropdown box to '%'. 2) Just set $cat to whatever you want, when it is 'x' if ($cat == 'x') { $cat = '%'; } Alexander. -- PHP General 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] Variable conversion problem
On Fri, 21 Sep 2001 11:15, Neil Silvester wrote: > Another PHP problem has kept me up all night, scouring through my > database books and trying everything I could think of. I am still new > to the MySQL and PHP field, but never the lass I will not give up. > $cat is a variable that is passed to the query from the previous page. > The SELECT statement works faultlessly, except for the point at which > no choice is made from the drop down on the page prior to this one. I > have set a value > > of "x" to the drop down for a non selection, but am having problems > converting that "x" value to a "%" value (the MySql wildcard symbol) > withing my SELECT statement. > I am assuming that I will need an IF THEN before the SELECT, but I have > tried several variation to no avail. > > $result = mysql_query("SELECT CompetitorName > FROM competitor, competitorproducts, productcategory > WHERE competitorproducts.CompID=competitor.ID > AND productcategory.ID=\"$cat\" > AND competitorproducts.CatID=productcategory.ID" > ); > > Any help would be mostly appreciated. > Thanks. > > Neil Silvester > Webmaster / Systems Administrator > Heat and Control Inc. There are several possible solutions here, starting with seting a default selection in your dropdown so you avoid the problem. Otherwise you could test whether the dropdown value is empty, and if so, not add the 'AND productcategory.ID' clause to your select. -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA "I've lived through a lot of windstorms," Tom regaled. -- PHP General 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] Variable conversion problem
Another PHP problem has kept me up all night, scouring through my database books and trying everything I could think of. I am still new to the MySQL and PHP field, but never the lass I will not give up. $cat is a variable that is passed to the query from the previous page. The SELECT statement works faultlessly, except for the point at which no choice is made from the drop down on the page prior to this one. I have set a value of "x" to the drop down for a non selection, but am having problems converting that "x" value to a "%" value (the MySql wildcard symbol) withing my SELECT statement. I am assuming that I will need an IF THEN before the SELECT, but I have tried several variation to no avail. $result = mysql_query("SELECT CompetitorName FROM competitor, competitorproducts, productcategory WHERE competitorproducts.CompID=competitor.ID AND productcategory.ID=\"$cat\" AND competitorproducts.CatID=productcategory.ID" ); Any help would be mostly appreciated. Thanks. Neil Silvester Webmaster / Systems Administrator Heat and Control Inc.
[PHP] variable arguments wish list
I the Sears Christmas catologe is out, Im going to make a christmas wish too. I wish I could just do this function test() { somefunc(func_get_args(), 'one more arg'); } but I cant, I have todo this, ouch function test() { $args = func_get_args(); eval("somefunc( '". implode("', '", $args) ."', 'one more arg' ); "; } thats just nasty. and dont try putting the func_get_args() in the implode, I get a warning saying dont even try it. plus it would still be ugly. -- Chris Lee [EMAIL PROTECTED] -- PHP General 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] Variable Syntax Question
From: * R&zE: <[EMAIL PROTECTED]> Date: Fri, Aug 31, 2001 at 04:36:36PM +0200 Message-ID: <[EMAIL PROTECTED]> Subject: Re: [PHP] Variable Syntax Question Btw... Why not just use an array? and then: foreach ($bob as $myValue) { print ($myValue); } That's a much nicer solution... -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- PHP General 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] Variable Syntax Question
From: Ninety-Nine Ways To Die <[EMAIL PROTECTED]> Date: Fri, Aug 31, 2001 at 10:28:56AM -0400 Message-ID: <[EMAIL PROTECTED]> Subject: [PHP] Variable Syntax Question > I have a form that reads in a couple variables via: > > > > > > > Now... I want to read in those variables in something like the following: > > for($i=1;$i<4;$i++) { >echo "$bob$i"; > } > > BUT that obviously doesn't work, it simple prints 1, so how to I make it echo >the value of the variable bob1? > > -Hass for ($i = 1; $i < 4; $i++) { $myVar = "bob$i"; print ($$myVar); } -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- PHP General 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] Variable Syntax Question
I have a form that reads in a couple variables via: Now... I want to read in those variables in something like the following: for($i=1;$i<4;$i++) { echo "$bob$i"; } BUT that obviously doesn't work, it simple prints 1, so how to I make it echo the value of the variable bob1? -Hass Get 250 color business cards for FREE! http://businesscards.lycos.com/vp/fastpath/ -- PHP General 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] variable variables and eval
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi All, i have come across a strange problem with variable variables. Basicly i'm doing the following and its not working: $section = 'data["SITE"][0]["NAME"][0]'; $pData = 'My Site.'; ${sprintf('$%s', $section)}.=$pData; but it is not working. But if i do this: eval('$'.$section.'.="'.addslashes($pData).'";'); it works and all is well. I don't really want to use eval() and just wanted to see if anybody has any ideas why the above doesn't work. Thanks, William. -BEGIN PGP SIGNATURE- Version: PGPfreeware 5.0i for non-commercial use Charset: noconv iQA/AwUBO3foS639EoU2VrU1EQIPZgCcCg643+F0xDUXdsBSYAYInFStaJ0An2ID AKL4hMIktbRsQpyVgkoeKsDo =w0ei -END PGP SIGNATURE- -- PHP General 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] variable $PATH_INFO
why can i read PATH_INFO server variable with apache under windows server ? with IIS 5 it's OK how can i ? -> Warning: Undefined variable: PATH_INFO in e:\sitephp\php_edit\htdocs\var.php on line 3 -- PHP General 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] Storing Java Script Varable into php variable
Hi Mike! Generally the only way to send information from a clientside javascript to a serverside language (in this case PHP) is via a form submit or putting that value into an HREF the user will click. For example: Save your screen settings... (please note: this is all rough code off the top of my lacking caffeine head...it has not been debugged or anything else. or in other words, it's an approximation. ;] ) Hope this helps, - Erik -- PHP General 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]