Re: [PHP] application level variable file
On Fri, Mar 22, 2013 at 10:22 AM, inu...@gmail.com wrote: I am very new to the PHP application and would like to create a new project. I would like to have a file to save my application level variable and functions. I would like to know does PHP have any default file name and file path for this file like Web.config file for ASP.Net and Application.cfm for ColdFusion? Your help and information is great appreciated, No. For more info: http://php.net/manual -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] application level variable file
2013/3/22 inu...@gmail.com I am very new to the PHP application and would like to create a new project. I would like to have a file to save my application level variable and functions. I would like to know does PHP have any default file name and file path for this file like Web.config file for ASP.Net and Application.cfm for ColdFusion? Your help and information is great appreciated, Do you mean index.php and Document-Root? Both is defined/configured by the webserver Regards, Inungh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] application level variable file
On 22 Mar 2013, at 14:22, inu...@gmail.com wrote: I am very new to the PHP application and would like to create a new project. I would like to have a file to save my application level variable and functions. I would like to know does PHP have any default file name and file path for this file like Web.config file for ASP.Net and Application.cfm for ColdFusion? No. Without the use of extensions, PHP follows a shared-nothing architecture. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] application level variable file
On Fri, Mar 22, 2013 at 10:26 AM, Stuart Dallas stu...@3ft9.com wrote: On 22 Mar 2013, at 14:22, inu...@gmail.com wrote: I am very new to the PHP application and would like to create a new project. I would like to have a file to save my application level variable and functions. I would like to know does PHP have any default file name and file path for this file like Web.config file for ASP.Net and Application.cfm for ColdFusion? You can in the php.ini file use this http://php.net/manual/en/ini.core.php#ini.auto-prepend-file *auto_prepend_file* stringhttp://www.php.net/manual/en/language.types.string.php Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the requirehttp://www.php.net/manual/en/function.require.php function, so include_path http://www.php.net/manual/en/ini.core.php#ini.include-path is used. The special value *none* disables auto-prepending.
Re: [PHP] Reading class variable value always returns NULL
So here's some new observations on the instance variables being NULL. As far as we found out this is the sequence of events: 1. Apache (MPM) received request A which executes a php script. 2. Within this script during the unserialization of an object an exception is thrown. 3. This exception is catched and an error message is display to standard output with echo. 4. The script ends normally and the standard output contents are returned in the HTTP response. 5. From now on this Apache worker is tainted, meaning that every subsequent request will result in: 6. The same apache worker receives request B which executes a PHP script. 7. Within this PHP script reading instance variables will always return NULL, e.g.: ?php class A{} $a = new A(); $a-foo = 1; // Now: $a-foo === NULL All subsequent requests to this apache worker will behave like this. The constellation leading to this behavior is very hard to further simplify. If we throw different exceptions, or unserialize different objects it doesn't happen anymore... As a workaround we added exit; to the end of our php script. With a call to exit the apache worker will not get tainted... Regards, Reto On Tue, Aug 14, 2012 at 11:52 PM, Reto Kaiser r...@cargomedia.ch wrote: Hey, We have: error_reporting((E_ALL | E_STRICT) ~(E_NOTICE | E_USER_NOTICE)); Displaying errors is disabled: display_errors = Off We have a custom error handler which logs all errors to a file. In this file we receive byeffect errors, like that the second argument to array_key_exists should be array, but is NULL. When we further debug the reason is that the second argument is an instance variable, and all instance variables are NULL. We're pretty sure this is a software bug, since it only happens from time to time, and already happens in the first line of the php script, when none of our application code was loaded. For example: ?php class A{} $a = new A(); $a-foo = 1; if ($a-foo === null) { throw new Exception(strange); } will throw an exception. Since it only happens from time to time, it is really hard to debug. We're now trying to reproduce in a virtual machine environment, while replaying the actual requests that our webserver received. When we're just simulating random load on the web server it doesn't happen. So it must have something to do with certain requests, and they must have some strange byeffect on php, or mod_php or something related. Any input welcome! Thanks, Reto On Tue, Aug 14, 2012 at 11:11 PM, Jim Lucas li...@cmsws.com wrote: On 08/12/2012 05:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. Does anyone have an idea what could cause this, or how to further debug? Thanks, Reto What is your error reporting set to? Do you have display errors turned on? Are you saving your errors to a log file? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading class variable value always returns NULL
As a little clarification: The Apache server in question is configured as a MPM prefork. On Wed, Aug 15, 2012 at 4:28 PM, Reto Kaiser r...@cargomedia.ch wrote: So here's some new observations on the instance variables being NULL. As far as we found out this is the sequence of events: 1. Apache (MPM) received request A which executes a php script. 2. Within this script during the unserialization of an object an exception is thrown. 3. This exception is catched and an error message is display to standard output with echo. 4. The script ends normally and the standard output contents are returned in the HTTP response. 5. From now on this Apache worker is tainted, meaning that every subsequent request will result in: 6. The same apache worker receives request B which executes a PHP script. 7. Within this PHP script reading instance variables will always return NULL, e.g.: ?php class A{} $a = new A(); $a-foo = 1; // Now: $a-foo === NULL All subsequent requests to this apache worker will behave like this. The constellation leading to this behavior is very hard to further simplify. If we throw different exceptions, or unserialize different objects it doesn't happen anymore... As a workaround we added exit; to the end of our php script. With a call to exit the apache worker will not get tainted... Regards, Reto On Tue, Aug 14, 2012 at 11:52 PM, Reto Kaiser r...@cargomedia.ch wrote: Hey, We have: error_reporting((E_ALL | E_STRICT) ~(E_NOTICE | E_USER_NOTICE)); Displaying errors is disabled: display_errors = Off We have a custom error handler which logs all errors to a file. In this file we receive byeffect errors, like that the second argument to array_key_exists should be array, but is NULL. When we further debug the reason is that the second argument is an instance variable, and all instance variables are NULL. We're pretty sure this is a software bug, since it only happens from time to time, and already happens in the first line of the php script, when none of our application code was loaded. For example: ?php class A{} $a = new A(); $a-foo = 1; if ($a-foo === null) { throw new Exception(strange); } will throw an exception. Since it only happens from time to time, it is really hard to debug. We're now trying to reproduce in a virtual machine environment, while replaying the actual requests that our webserver received. When we're just simulating random load on the web server it doesn't happen. So it must have something to do with certain requests, and they must have some strange byeffect on php, or mod_php or something related. Any input welcome! Thanks, Reto On Tue, Aug 14, 2012 at 11:11 PM, Jim Lucas li...@cmsws.com wrote: On 08/12/2012 05:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. Does anyone have an idea what could cause this, or how to further debug? Thanks, Reto What is your error reporting set to? Do you have display errors turned on? Are you saving your errors to a log file? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/
Re: [PHP] Reading class variable value always returns NULL
Hi, Thanks for your input Robert and Volmar! I have googled again with instance variable instead of class variable - but have not found any similar reports. I'm pretty sure those are the same objects. The application usually runs alright. We only see the instance variables becoming NULL since about a week. We had 3 small software upgrade coming from debian since we observe the problem. We think they cannot be related. Still we have reverted all of those and still see the problem. Next step is that we setup a exact copy of the machine. Maybe it is a hardware problem... Thanks, Reto On Mon, Aug 13, 2012 at 5:09 PM, Robert Cummings rob...@interjinn.com wrote: On 12-08-12 08:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. The class has one variable declared: = class A { private $_cookies; } = That is a private instance variable NOT a class variable. To declare a class variable you would do the following: ?php class A { private static $_cookies; } ? In a method of this class I assign this classvariable plus an undeclared classvariable and a local variable the value 1: = $this-_cookies = 1; $this-_cookies2 = 1; $cookies3 = 1; = When I now read the values of those variables, the classvariables are NULL while the local variable is 1: = $logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL; $logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL; $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL; = cookies: NULL cookies2: NULL cookies3: 1 = But when reading the whole object, the classvariables are 1: = $logEntry .= var_export($this, true) . PHP_EOL; = A::__set_state(array( '_cookies' = 1, '_cookies2' = 1, )) = This happens periodically on a busy webserver. It seems that when it happens, all classvariables cannot be read anymore (return NULL). After restarting Apache it does not happen anymore, just to happen again after some minutes. The system is current Debian Squeeze: Linux: linux-image-2.6.32-5-amd64 Apache: apache2-mpm-prefork 2.2.16-6+squeeze7 PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10 2012 07:31:32) php -m: https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt php -i: https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt Does anyone have an idea what could cause this, or how to further debug? I can't really speak to your specific problem (unless you're using two different instances of the class), just thought I'd clear up the difference between class variables and instance variables. Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading class variable value always returns NULL
Hi, We have since deployed another webserver machine and observe the exact same behavior there. So it is not a hardware problem. We have also disabled various php modules, but this didn't help either. Any debug suggestions are welcome! :) Reto On Tue, Aug 14, 2012 at 10:40 AM, Reto Kaiser r...@cargomedia.ch wrote: Hi, Thanks for your input Robert and Volmar! I have googled again with instance variable instead of class variable - but have not found any similar reports. I'm pretty sure those are the same objects. The application usually runs alright. We only see the instance variables becoming NULL since about a week. We had 3 small software upgrade coming from debian since we observe the problem. We think they cannot be related. Still we have reverted all of those and still see the problem. Next step is that we setup a exact copy of the machine. Maybe it is a hardware problem... Thanks, Reto On Mon, Aug 13, 2012 at 5:09 PM, Robert Cummings rob...@interjinn.com wrote: On 12-08-12 08:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. The class has one variable declared: = class A { private $_cookies; } = That is a private instance variable NOT a class variable. To declare a class variable you would do the following: ?php class A { private static $_cookies; } ? In a method of this class I assign this classvariable plus an undeclared classvariable and a local variable the value 1: = $this-_cookies = 1; $this-_cookies2 = 1; $cookies3 = 1; = When I now read the values of those variables, the classvariables are NULL while the local variable is 1: = $logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL; $logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL; $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL; = cookies: NULL cookies2: NULL cookies3: 1 = But when reading the whole object, the classvariables are 1: = $logEntry .= var_export($this, true) . PHP_EOL; = A::__set_state(array( '_cookies' = 1, '_cookies2' = 1, )) = This happens periodically on a busy webserver. It seems that when it happens, all classvariables cannot be read anymore (return NULL). After restarting Apache it does not happen anymore, just to happen again after some minutes. The system is current Debian Squeeze: Linux: linux-image-2.6.32-5-amd64 Apache: apache2-mpm-prefork 2.2.16-6+squeeze7 PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10 2012 07:31:32) php -m: https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt php -i: https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt Does anyone have an idea what could cause this, or how to further debug? I can't really speak to your specific problem (unless you're using two different instances of the class), just thought I'd clear up the difference between class variables and instance variables. Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading class variable value always returns NULL
I'm not real clear on what's happening. Are you saying that if you assign values to the protected class members, and then immediately read them, that they're null? So, there's code something like this: class Foo { public function Something() { $this-foo = 1; //shows null instead of 1 var_dump($this-foo); } protected $foo; } Is that right? Regards, Bob -- Robert E. Williams, Jr. Associate Vice President of Software Development Newtek Businesss Services, Inc. -- The Small Business Authority https://www.newtekreferrals.com/rewjr http://www.thesba.com/ Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading class variable value always returns NULL
On 08/12/2012 05:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. Does anyone have an idea what could cause this, or how to further debug? Thanks, Reto What is your error reporting set to? Do you have display errors turned on? Are you saving your errors to a log file? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading class variable value always returns NULL
Hey, We have: error_reporting((E_ALL | E_STRICT) ~(E_NOTICE | E_USER_NOTICE)); Displaying errors is disabled: display_errors = Off We have a custom error handler which logs all errors to a file. In this file we receive byeffect errors, like that the second argument to array_key_exists should be array, but is NULL. When we further debug the reason is that the second argument is an instance variable, and all instance variables are NULL. We're pretty sure this is a software bug, since it only happens from time to time, and already happens in the first line of the php script, when none of our application code was loaded. For example: ?php class A{} $a = new A(); $a-foo = 1; if ($a-foo === null) { throw new Exception(strange); } will throw an exception. Since it only happens from time to time, it is really hard to debug. We're now trying to reproduce in a virtual machine environment, while replaying the actual requests that our webserver received. When we're just simulating random load on the web server it doesn't happen. So it must have something to do with certain requests, and they must have some strange byeffect on php, or mod_php or something related. Any input welcome! Thanks, Reto On Tue, Aug 14, 2012 at 11:11 PM, Jim Lucas li...@cmsws.com wrote: On 08/12/2012 05:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. Does anyone have an idea what could cause this, or how to further debug? Thanks, Reto What is your error reporting set to? Do you have display errors turned on? Are you saving your errors to a log file? -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading class variable value always returns NULL
On 12-08-12 08:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. The class has one variable declared: = class A { private $_cookies; } = That is a private instance variable NOT a class variable. To declare a class variable you would do the following: ?php class A { private static $_cookies; } ? In a method of this class I assign this classvariable plus an undeclared classvariable and a local variable the value 1: = $this-_cookies = 1; $this-_cookies2 = 1; $cookies3 = 1; = When I now read the values of those variables, the classvariables are NULL while the local variable is 1: = $logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL; $logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL; $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL; = cookies: NULL cookies2: NULL cookies3: 1 = But when reading the whole object, the classvariables are 1: = $logEntry .= var_export($this, true) . PHP_EOL; = A::__set_state(array( '_cookies' = 1, '_cookies2' = 1, )) = This happens periodically on a busy webserver. It seems that when it happens, all classvariables cannot be read anymore (return NULL). After restarting Apache it does not happen anymore, just to happen again after some minutes. The system is current Debian Squeeze: Linux: linux-image-2.6.32-5-amd64 Apache: apache2-mpm-prefork 2.2.16-6+squeeze7 PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10 2012 07:31:32) php -m: https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt php -i: https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt Does anyone have an idea what could cause this, or how to further debug? I can't really speak to your specific problem (unless you're using two different instances of the class), just thought I'd clear up the difference between class variables and instance variables. Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Reading class variable value always returns NULL
It's only a hint, but You start checking if the Object Ids are the same or not. 2012/8/13 Robert Cummings rob...@interjinn.com: On 12-08-12 08:32 AM, Reto Kaiser wrote: Hi, So I have this strange situation where I assign a classvariable a value, but when I read the value it is NULL. The class has one variable declared: = class A { private $_cookies; } = That is a private instance variable NOT a class variable. To declare a class variable you would do the following: ?php class A { private static $_cookies; } ? In a method of this class I assign this classvariable plus an undeclared classvariable and a local variable the value 1: = $this-_cookies = 1; $this-_cookies2 = 1; $cookies3 = 1; = When I now read the values of those variables, the classvariables are NULL while the local variable is 1: = $logEntry .= 'cookies: ' . var_export($this-_cookies, true) . PHP_EOL; $logEntry .= 'cookies2: ' . var_export($this-_cookies2, true) . PHP_EOL; $logEntry .= 'cookies3: ' . var_export($cookies3, true) . PHP_EOL; = cookies: NULL cookies2: NULL cookies3: 1 = But when reading the whole object, the classvariables are 1: = $logEntry .= var_export($this, true) . PHP_EOL; = A::__set_state(array( '_cookies' = 1, '_cookies2' = 1, )) = This happens periodically on a busy webserver. It seems that when it happens, all classvariables cannot be read anymore (return NULL). After restarting Apache it does not happen anymore, just to happen again after some minutes. The system is current Debian Squeeze: Linux: linux-image-2.6.32-5-amd64 Apache: apache2-mpm-prefork 2.2.16-6+squeeze7 PHP: PHP 5.3.3-7+squeeze13 with Suhosin-Patch (cli) (built: Jun 10 2012 07:31:32) php -m: https://raw.github.com/gist/3331641/2f7e80bd03abfb728b659634d3f4bac0131f4d6a/gistfile1.txt php -i: https://raw.github.com/gist/3331651/bcf6e3654bf391482627505447848de173d0bbab/gistfile1.txt Does anyone have an idea what could cause this, or how to further debug? I can't really speak to your specific problem (unless you're using two different instances of the class), just thought I'd clear up the difference between class variables and instance variables. Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- 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] Read dynamic variable from HTML form into PHP
There are essentially 2 ways: 1. All POSTed data is present in the $_POST superglobal array. So you could just loop over that, ignore the fields you already knew were there, and the data remaining is then essentially the data you seek. The keys in the $_POST array are the fieldnames you are looking for. 2. There's a special trick in PHP, when you name a field name[] in HTML and then POST it to a PHP script, it will turn into an array field. So input name=a[] value=1 input name=a[] value=2 will then end up in: $_POST = [ 'a' = [ 0 = '1', 1 = '2' ] ] If you had not added the square-brackets, you would have: input name=a value=1 input name=a value=2 ending up in: $_POST = [ 'a' = '2' ] Thus not ever seeing the value '1'. form checkbox field name=input_1 value=y checkbox field name=input_2 value=y field name input_n .. /form ? //checkboxes return on submit only if ticked $query=SELECT id FROM table WHERE etc; $result=mysql_db_query($db, $query,$connection); $count=mysql_num_rows($result); while($row=mysql_fetch_row($result)) { $id=$row[0]; //dynamic variable //if form uses textfield that returns on submit //if(${input_.$id}==1){ //if checkbox that only returns if ticked if(ISSET(${input_.$id})){ echo checked 1; } } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Read dynamic variable from HTML form into PHP
On 06-06-2012 05:11, Jim Giner wrote: Govindagovinda.webdnat...@gmail.com wrote in message news:72497398-3a6c-4faa-89f2-565c18fd2...@gmail.com... On 2012-06-05, at 10:54 PM, Devangnp wrote: I know how to pass variable but having difficulties when I use the dynamic form field in HTML that add more boxes as per user require. Hi All, I am a basic user of PHP and I have need of reading the dynamic HTML form field as a variable in PHP so it will be great if someone can share some good link or snip for quick understanding. Thanks, Devang http://lmgtfy.com/?q=how+to+pass+and+receive+a+PHP+variable When just starting out, Google is your friend. Or did I misunderstand your question? -Govinda Devang, Please keep replies on-list. Please post your replies at the bottom, past the older (snipped) content. Many here will be glad to help.. but you'll need to make your question more clear.. at least for me to be able to help anyway. First of all, what do you mean exactly, by, the dynamic form field in HTML? And by boxes do you mean form inputs of 'text' type? If so, then do you mean to suggest that input by the end user should determine the number of text inputs that should display in a second HTML form? Please spend more time describing what you are trying to do.. and also please show any code you attempt(ed) to accomplish this. If you are unable to write any code, then try pseudo code - meaning write in successive lines of prose what you want code to do, and post that here. -Govinda= I thought he meant previously generated array type fields, that use the same name. I've never done it myself, but I thought the method of handling this kind of input included placing a hidden field with the count on the form to be retriieved later and used in processing the dynamic fields in a loop. A possible answer to a possible question that he might have (yes, the question is very vaguely described, as Govinda already explained) would be the following: Assuming you have an HTML form, which may contain a variable number of fields, you want to somehow access their passed-through values in PHP without prior knowledge of the exact number of those fields. There are essentially 2 ways: 1. All POSTed data is present in the $_POST superglobal array. So you could just loop over that, ignore the fields you already knew were there, and the data remaining is then essentially the data you seek. The keys in the $_POST array are the fieldnames you are looking for. 2. There's a special trick in PHP, when you name a field name[] in HTML and then POST it to a PHP script, it will turn into an array field. So input name=a[] value=1 input name=a[] value=2 will then end up in: $_POST = [ 'a' = [ 0 = '1', 1 = '2' ] ] If you had not added the square-brackets, you would have: input name=a value=1 input name=a value=2 ending up in: $_POST = [ 'a' = '2' ] Thus not ever seeing the value '1'. I hope this answers part of your question; and if not, PLEASE explain in more detail what your problem is, what you tried, why it didn't work, and what you want to know exactly. Your current question is very very short and vague enough to easily cause misunderstanding. - Tul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Read dynamic variable from HTML form into PHP
Maciek Sokolewicz maciek.sokolew...@gmail.com wrote in message news:4fcf23af.7040...@php.net... On 06-06-2012 05:11, Jim Giner wrote: Govindagovinda.webdnat...@gmail.com wrote in message news:72497398-3a6c-4faa-89f2-565c18fd2...@gmail.com... On 2012-06-05, at 10:54 PM, Devangnp wrote: I know how to pass variable but having difficulties when I use the dynamic form field in HTML that add more boxes as per user require. Hi All, I am a basic user of PHP and I have need of reading the dynamic HTML form field as a variable in PHP so it will be great if someone can share some good link or snip for quick understanding. Thanks, Devang http://lmgtfy.com/?q=how+to+pass+and+receive+a+PHP+variable When just starting out, Google is your friend. Or did I misunderstand your question? -Govinda Devang, Please keep replies on-list. Please post your replies at the bottom, past the older (snipped) content. Many here will be glad to help.. but you'll need to make your question more clear.. at least for me to be able to help anyway. First of all, what do you mean exactly, by, the dynamic form field in HTML? And by boxes do you mean form inputs of 'text' type? If so, then do you mean to suggest that input by the end user should determine the number of text inputs that should display in a second HTML form? Please spend more time describing what you are trying to do.. and also please show any code you attempt(ed) to accomplish this. If you are unable to write any code, then try pseudo code - meaning write in successive lines of prose what you want code to do, and post that here. -Govinda= I thought he meant previously generated array type fields, that use the same name. I've never done it myself, but I thought the method of handling this kind of input included placing a hidden field with the count on the form to be retriieved later and used in processing the dynamic fields in a loop. A possible answer to a possible question that he might have (yes, the question is very vaguely described, as Govinda already explained) would be the following: Assuming you have an HTML form, which may contain a variable number of fields, you want to somehow access their passed-through values in PHP without prior knowledge of the exact number of those fields. There are essentially 2 ways: 1. All POSTed data is present in the $_POST superglobal array. So you could just loop over that, ignore the fields you already knew were there, and the data remaining is then essentially the data you seek. The keys in the $_POST array are the fieldnames you are looking for. 2. There's a special trick in PHP, when you name a field name[] in HTML and then POST it to a PHP script, it will turn into an array field. So input name=a[] value=1 input name=a[] value=2 will then end up in: $_POST = [ 'a' = [ 0 = '1', 1 = '2' ] ] If you had not added the square-brackets, you would have: input name=a value=1 input name=a value=2 ending up in: $_POST = [ 'a' = '2' ] Thus not ever seeing the value '1'. I hope this answers part of your question; and if not, PLEASE explain in more detail what your problem is, what you tried, why it didn't work, and what you want to know exactly. Your current question is very very short and vague enough to easily cause misunderstanding. - Tul Thank you Tul for your eloquent post. Now I understand how to handle those kinds of array inputs myself! And - I do think from his vague description that the OP is looking for this kind of help. If not, then it was REALLY vague! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Read dynamic variable from HTML form into PHP
Hi All, I am a basic user of PHP and I have need of reading the dynamic HTML form field as a variable in PHP so it will be great if someone can share some good link or snip for quick understanding. Thanks, Devang http://lmgtfy.com/?q=how+to+pass+and+receive+a+PHP+variable When just starting out, Google is your friend. Or did I misunderstand your question? -Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Read dynamic variable from HTML form into PHP
On 2012-06-05, at 10:54 PM, Devangnp wrote: I know how to pass variable but having difficulties when I use the dynamic form field in HTML that add more boxes as per user require. Hi All, I am a basic user of PHP and I have need of reading the dynamic HTML form field as a variable in PHP so it will be great if someone can share some good link or snip for quick understanding. Thanks, Devang http://lmgtfy.com/?q=how+to+pass+and+receive+a+PHP+variable When just starting out, Google is your friend. Or did I misunderstand your question? -Govinda Devang, Please keep replies on-list. Please post your replies at the bottom, past the older (snipped) content. Many here will be glad to help.. but you'll need to make your question more clear.. at least for me to be able to help anyway. First of all, what do you mean exactly, by, the dynamic form field in HTML? And by boxes do you mean form inputs of 'text' type? If so, then do you mean to suggest that input by the end user should determine the number of text inputs that should display in a second HTML form? Please spend more time describing what you are trying to do.. and also please show any code you attempt(ed) to accomplish this. If you are unable to write any code, then try pseudo code - meaning write in successive lines of prose what you want code to do, and post that here. -Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Read dynamic variable from HTML form into PHP
Govinda govinda.webdnat...@gmail.com wrote in message news:72497398-3a6c-4faa-89f2-565c18fd2...@gmail.com... On 2012-06-05, at 10:54 PM, Devangnp wrote: I know how to pass variable but having difficulties when I use the dynamic form field in HTML that add more boxes as per user require. Hi All, I am a basic user of PHP and I have need of reading the dynamic HTML form field as a variable in PHP so it will be great if someone can share some good link or snip for quick understanding. Thanks, Devang http://lmgtfy.com/?q=how+to+pass+and+receive+a+PHP+variable When just starting out, Google is your friend. Or did I misunderstand your question? -Govinda Devang, Please keep replies on-list. Please post your replies at the bottom, past the older (snipped) content. Many here will be glad to help.. but you'll need to make your question more clear.. at least for me to be able to help anyway. First of all, what do you mean exactly, by, the dynamic form field in HTML? And by boxes do you mean form inputs of 'text' type? If so, then do you mean to suggest that input by the end user should determine the number of text inputs that should display in a second HTML form? Please spend more time describing what you are trying to do.. and also please show any code you attempt(ed) to accomplish this. If you are unable to write any code, then try pseudo code - meaning write in successive lines of prose what you want code to do, and post that here. -Govinda= I thought he meant previously generated array type fields, that use the same name. I've never done it myself, but I thought the method of handling this kind of input included placing a hidden field with the count on the form to be retriieved later and used in processing the dynamic fields in a loop. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Error in variable assignment
On 11 April 2011 20:28, Ethan Rosenberg eth...@earthlink.net wrote: Dear list - I an writing a script that will simulate a chess board. On a move from e2 to e6 [see below] the variable in e2 is never assigned to e6. Here are some code snippets: ?php session_start(); session_name(Chess); error_reporting(1); if ($_SESSION['flag'] != 1) { $flag = 1; echo br /startingbr /; $results = array(array(Br, Bn, Bb, Bq, Bk, Bb, Bn, Br),array(Bp, Bp, Bp, Bp, Bp, Bp, Bp, Bp), array(, , , , , , , ),array(, , , , , , , ),array(, , , , , , , ), array(, , , , , , , ),array(Wp, Wp, Wp, Wp, Wp, Wp, Wp, Wp), array(Wr, Wn, Wb, Wq, Wk, Wb, Wn, Wr)); $_SESSION['results'] = $results; for($i = 0; $i 8; $i++) { for ($j = 0; $j 8; $j++) printf(%s , $results[$i][$j]); printf(br /); } $_SESSION[flag] = $flag; snip $board = array //Correlation of input array [chessboard] with internal array [results] ( a8 = $results[0][0], b8 = $results[0][1], c8 = $results[0][2], d8 = $results[0][3], e8 = $results[0][4], f8 = $results[0][5], g8 = $results[0][6], h8 = $results[0][7], a7 = $results[1][0], b7 = $results[1][1], c7 = $results[1][2], d7 = $results[1][3], e7 = $results[1][4], f7 = $results[1][5], g7 = $results[1][6], h7 = $results[1][7], a6 = $results[2][0], b6 = $results[2][1], c6 = $results[2][2], d6 = $results[2][3], e6 = $results[2][4], f6 = $results[2][5], g6 = $results[2][6], h6 = $results[2][7], a5 = $results[3][0], b5 = $results[3][1], c5 = $results[3][2], d5 = $results[3][3], e5 = $results[3][4], f5 = $results[3][5], g5 = $results[3][6], h5 = $results[3][7], a4 = $results[4][0], b4 = $results[4][1], c4 = $results[4][2], d4 = $results[4][3], e4 = $results[4][4], f4 = $results[4][5], g4 = $results[4][6], h4 = $results[4][7], a3 = $results[5][0], b3 = $results[5][1], c3 = $results[5][2], d3 = $results[5][3], e3 = $results[5][4], f3 = $results[5][5], g3 = $results[5][6], h3 = $results[5][7], a2 = $results[6][0], b2 = $results[6][1], c2 = $results[6][2], d2 = $results[6][3], e2 = $results[6][4], f2 = $results[6][5], g2 = $results[6][6], h2 = $results[6][7], a1 = $results[7][0], b1 = $results[7][1], c1 = $results[7][2], d1 = $results[7][3], e1 = $results[7][4], f1 = $results[7][5], g1 = $results[7][6], h1 = $results[7][7], ); $board2 = array //Correlation of input array [chessboard] with internal array [results] ( a8 = [0][0], b8 = [0][1], c8 = [0][2], d8 = [0][3], e8 = [0][4], f8 = [0][5], g8 = [0][6], h8 = [0][7], a7 = [1][0], b7 = [1][1], c7 = [1][2], d7 = [1][3], e7 = [1][4], f7 = [1][5], g7 = [1][6], h7 = [1][7], a6 = [2][0], b6 = [2][1], c6 = [2][2], d6 = [2][3], e6 = [2][4], f6 = [2][5], g6 = [2][6], h6 = [2][7], a5 = [3][0], b5 = [3][1], c5 = [3][2], d5 = [3][3], e5 = [3][4], f5 = [3][5], g5 = [3][6], h5 = [3][7], a4 = [4][0], b4 = [4][1], c4 = [4][2], d4 = [4][3], e4 = [4][4], f4 = [4][5], g4 = [4][6], h4 = [4][7], a3 = [5][0], b3 = [5][1], c3 = [5][2], d3 = [5][3], e3 = [5][4], f3 = [5][5], g3 = [5][6], h3 = [5][7], a2 = [6][0], b2 = [6][1],
Re: [PHP] Re: $_POST variable
You could use foreach to iterate through the post variables until you encounter a match: foreach ($_POST as $key = $value){ if (substr($key, 0, 6) == radio_) { $buttonName = $key; $buttonValue = 4value; break 2; } } I haven't tried the above code, but I hope someone will correct my efforts if I'm wrong. given your code example - 'break 2;' -- s/b just 'break;' ... 'break 2;' is to exit the outer loop of a nested loop which is not the case here. Rich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: $_POST variable
On 3/11/2011 12:03 PM, Shawn McKenzie wrote: On 03/11/2011 01:28 PM, Danny wrote: Hi guys, I have a form that has a long list of radio-bottons inside of it. The radio-buttons are dynamically created via php and MySQL. Here is an example of one of the radio buttons: input type=radio name=?php print (radio_.$result_from_mysql) ; ? value=0 input type=radio name=?php print (radio_.$result_from_mysql) ; ? value=1 Now, when I submit this form to another page for processing, how would I catch the above radio-button's $_POST name since I do not know the name, only that it starts with radio_ ? Thank You Danny The most common and flexible way to do this sort of thing is to use arrays instead: input type=radio name=radio[?php echo $result_from_mysql; ?] value=0 input type=radio name=radio[?php echo $result_from_mysql; ?] value=1 Then: foreach($_POST['radio'] as $key = $value) { echo radio for $key is $value; } Your example would be good if the OP wanted checkbox'es. But with radio buttons, the whole point (most of the time) is to have the form only allow you to have one of the radio input fields selected at any given time. How you showed it, it would not see the uniqueness of the radio button names, and therefor allow more than one of the radio input fields to be selected at a time. I would try something like this: As long as this is correct: input type=radio name=radio_?php echo $result_from_mysql; ? value=0 /Zero input type=radio name=radio_?php echo $result_from_mysql; ? value=1 /One Then I would do the following: foreach ($_POST as $k = $v) { if ( strpos(trim($k), 'radio_') === 0 ) { echo $k.' is a match, and it\'s value is '.$v.'.br/'.PHP_EOL; } } Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: $_POST variable
On 03/11/2011 02:33 PM, Jim Lucas wrote: On 3/11/2011 12:03 PM, Shawn McKenzie wrote: On 03/11/2011 01:28 PM, Danny wrote: Hi guys, I have a form that has a long list of radio-bottons inside of it. The radio-buttons are dynamically created via php and MySQL. Here is an example of one of the radio buttons: input type=radio name=?php print (radio_.$result_from_mysql) ; ? value=0 input type=radio name=?php print (radio_.$result_from_mysql) ; ? value=1 Now, when I submit this form to another page for processing, how would I catch the above radio-button's $_POST name since I do not know the name, only that it starts with radio_ ? Thank You Danny The most common and flexible way to do this sort of thing is to use arrays instead: input type=radio name=radio[?php echo $result_from_mysql; ?] value=0 input type=radio name=radio[?php echo $result_from_mysql; ?] value=1 Then: foreach($_POST['radio'] as $key = $value) { echo radio for $key is $value; } Your example would be good if the OP wanted checkbox'es. But with radio buttons, the whole point (most of the time) is to have the form only allow you to have one of the radio input fields selected at any given time. How you showed it, it would not see the uniqueness of the radio button names, and therefor allow more than one of the radio input fields to be selected at a time. One radio button of the same name selected at a time yes. From the OP's code of two radios, one with value 0 and one with value 1, I assumed these were to be a pair with the same name with only one able to be successful. This extends to arrays as well: input type=radio name=radio[] value=0 input type=radio name=radio[] value=1 input type=radio name=radio[555] value=0 input type=radio name=radio[555] value=1 This works as expected, the same as the code I posted. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: $_POST variable
On 3/11/2011 2:43 PM, Geoff Lane wrote: [snip] You could use foreach to iterate through the post variables until you encounter a match: foreach ($_POST as $key = $value){ if (substr($key, 0, 6) == radio_) { $buttonName = $key; $buttonValue = 4value; break 2; } } I haven't tried the above code, but I hope someone will correct my efforts if I'm wrong. ok, now I am very new to php, so if i got this wrong be nice. It APPEARS TO ME that you are setting a variable called buttonName to the extracted value stored in $key for each name in the post submission, and a variable named buttonValue for the item's value. THEM, you do the same thing again to the same destination variables for the next name/value pair, and so-on until they list of name/value pairs is exhausted. IF this understanding is correct, only the LAST name/value pair will emerge from the process intact; prior values will be obliterated. Would they not be better to append them to a single dimensioned array, which starts life as a null array? If I am getting this wrong, please administer wet mackerel therapy to my tired head and explain the facts. -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Singleton with variable parameters
On Wed, Dec 15, 2010 at 2:11 PM, Sebastian Detert php-maill...@elygor.dewrote: Hi guys, I am trying to generate an abstract Singleton class for use in arbitrary classes, like class Foo extends Singleton {} and generate a new class with Foo - getInstance(); Until traits release I think you'll find this painful as any class that extends Singleton must now have extra functionality imbued via interfaces and composition. You will probly prefer to use a registry, something like Registry::getInstance('classname', array('parameters')); Even if you go with an abstract base class you will want an array of instances internally. How can I manage to use this with an unkown number of parameters like Foo - getInstance('a', 'b'); ? yes, func_get_args() call_user_func_array() however, fyi, these are very slow. Something like self::$instance = call_user_func (array(static , __construct), func_get_args()); instead of self::$instance = new self; doesn't work and an eval() is too slow. if performance is a concern why not use setters to establish state on all of your classes and keep the getInstance method down to 0 params. As long as your singletons aren't immutable this should work just fine. -nathan
RE: [PHP] Singleton with variable parameters
-Original Message- From: Nathan Nobbe [mailto:quickshif...@gmail.com] Sent: Wednesday, December 15, 2010 1:31 PM To: Sebastian Detert Cc: php-general@lists.php.net Subject: Re: [PHP] Singleton with variable parameters On Wed, Dec 15, 2010 at 2:11 PM, Sebastian Detert php- maill...@elygor.dewrote: Hi guys, I am trying to generate an abstract Singleton class for use in arbitrary classes, like class Foo extends Singleton {} and generate a new class with Foo - getInstance(); Until traits release I think you'll find this painful as any class that extends Singleton must now have extra functionality imbued via interfaces and composition. You will probly prefer to use a registry, something like Registry::getInstance('classname', array('parameters')); Even if you go with an abstract base class you will want an array of instances internally. How can I manage to use this with an unkown number of parameters like Foo - getInstance('a', 'b'); ? yes, func_get_args() call_user_func_array() however, fyi, these are very slow. Something like self::$instance = call_user_func (array(static , __construct), func_get_args()); instead of self::$instance = new self; doesn't work and an eval() is too slow. if performance is a concern why not use setters to establish state on all of your classes and keep the getInstance method down to 0 params. As long as your singletons aren't immutable this should work just fine. -nathan Sebastian, If you need to have some way to keep track of all the instances of subclasses and be able to communicate between them, then you'll have need to have the self::$instances = array() in the base class, as Nathan mentioned. But implementing instance map in the base abstract is unnecessary, IMO, as it could get very messy in the long run. I suggest you look into Interfaces. It will help make your code easier to manage in the future as your app gets more sophisticated. Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] curl and variable parameters in hyperlink
foreach ($_POST as $key=$post) { $post=str_replace( , +, $post); $url.=$key.=.$post.; } Hi Bob, One thing I see is that you're appending values on to the end of a url that already has 2 values, so you should place the at the beginning of your line instead of at the end. Value 2 is being merged with whatever value is coming after it in your example. So, try something like: $url .= . $key. = .$post; Also, I'd suggest url encoding the post value rather than merely hunting down spaces and swapping them out with +. Hope this helps, Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP] curl and variable parameters in hyperlink
On Wednesday 24 November 2010, Bob Keightley bob.keight...@virgin.net wrote: I already have a curl script that gets the web page, but it doesn't pass the parameters Hello Bob, Being new to PHP I haven't the first idea how to modify it so that it does. Script is as follows: $url = http://www.xx.com/query.asp?param1=val1param2=val2;; foreach ($_POST as $key=$post) { $post=str_replace( , +, $post); $url.=$key.=.$post.; } Instead of concatenating strings, I suggest to use the http_build_query() function: ?php $data = array('param1' = 'val1', 'param2' = 'val2', 'param3' = 'val3'); $query = http_build_query($data); echo Query: {$query}\n; ? So, to create a query string based on your $_POST request parameters, you just need to use the function as follows: ?php $query = http_build_query($_POST); echo Query: {$query}\n; ? This will create the proper query string to be used on your URL. $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); $data = curl_exec($ch); curl_close($ch); $data=str_replace('.asp', '.php', $data); echo $data; This returns the web page, but ignores val1 and val2 which are necessary to execute the query. Best regards, -- Daniel Molina Wegener dmw [at] coder [dot] cl System Programmer Web Developer Phone: +56 (2) 979-0277 | Blog: http://coder.cl/ signature.asc Description: This is a digitally signed message part.
Re: [PHP] curl and variable parameters in hyperlink
Guess I've not explained this very well. The external page I am fetching using another curl script has asp query hyperlinks in it. I do not know the variable names in each query or the values they have. All I want to do is replace the external url referenced in those links with a url which is on my site (so that I can change style sheet, image locations etc.) but the parameters to the original asp query link have to be captured and passed to my php script for it to return data. I know there must be a way of doing this as there's a site which is referencing the same third party site and doing the same thing, and no, they won't tell me how! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] curl and variable parameters in hyperlink
-Original Message- From: Bob Keightley [mailto:bob.keight...@virgin.net] Sent: Wednesday, November 24, 2010 11:25 AM To: php-general@lists.php.net Subject: Re: [PHP] curl and variable parameters in hyperlink Guess I've not explained this very well. The external page I am fetching using another curl script has asp query hyperlinks in it. I do not know the variable names in each query or the values they have. All I want to do is replace the external url referenced in those links with a url which is on my site (so that I can change style sheet, image locations etc.) but the parameters to the original asp query link have to be captured and passed to my php script for it to return data. I know there must be a way of doing this as there's a site which is referencing the same third party site and doing the same thing, and no, they won't tell me how! Bob, There's several issues with this. 1) They're providing the info which you're trying to pass it as your own and most likely that they won't get any positive results, as some company do analysis on visits to improve the marketing strategy, customer service, customer relations, etc. You're just skewing their data analysis and prevent them from becoming successful. Which may force them to go out of business then you'll lose your source of information. 2) Waste of bandwidth. 3rd party you user instead of just you user. 3) I'm don't like that fact that some people take others work and try to pass it as their own. I think many folks on this list feels the same way. So why not just quote them and give them the credit they deserve. That's probably the reason why you're not able to find much info on how to do this :) Regards, Tommy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] curl and variable parameters in hyperlink
Thanks to all for your interest so far but as I said, new to PHP. Changed POST to GET and all now working fine! Tommy, the third party site is fully aware of what I am doing. We pay them to use the data, as do lots of other companies in our industry. Supplying data is what they do. We could not use the site at all without being given a valid user name. Far from 'preventing them being successful' the more users they have the more successful they become. We do not 'pass the work as our own' they are credited on our site as suppliers of the content, so there really is no issue there. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] curl and variable parameters in hyperlink
Depending on how the website is setup you can curl or soap parameters. http://www.php.net/manual/en/book.curl.php http://www.php.net/manual/en/book.soap.php Richard L. Buskirk -Original Message- From: Bob Keightley [mailto:bob.keight...@virgin.net] Sent: Tuesday, November 23, 2010 9:12 PM To: php-general@lists.php.net Subject: [PHP] curl and variable parameters in hyperlink First use of Curl so probably a very simple problem - I have a script which loads a third party web page into my site. That page contains links which have variable parameters i.e. www.blahblah.asp?param1=xxxparam2=yyy. Any clues as to what I need to do to pass these parameters in a curl script appreciated. -- 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] curl and variable parameters in hyperlink
I already have a curl script that gets the web page, but it doesn't pass the parameters Being new to PHP I haven't the first idea how to modify it so that it does. Script is as follows: $url = http://www.xx.com/query.asp?param1=val1param2=val2;; foreach ($_POST as $key=$post) { $post=str_replace( , +, $post); $url.=$key.=.$post.; } $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); $data = curl_exec($ch); curl_close($ch); $data=str_replace('.asp', '.php', $data); echo $data; This returns the web page, but ignores val1 and val2 which are necessary to execute the query. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with variable variables not being set for a multi-dimensional array
On Tue, Nov 9, 2010 at 6:55 PM, Daevid Vincent dae...@daevid.com wrote: I've used variable variables before but for some reason I can't figure this snippet out. Why doesn't $ini_file get set (or appended to). AFAIK variable variables can only reference actual variables--not array subscripts or other non-variable syntax elements such as - or ::. eval() can do this because it parses the code as PHP. Variable variables take the *variable name* contained in the variable and look it up in the current scope. This is a variable name: ini_array This is not: ini_array['agis_core']['adapter'] I think you can use references here to do what you need. Warning: I only tested the basics of this in the interpreter without running this exact code. public function explode_ini() { $ini_array = array(); foreach($this-ini_array as $heading = $key_vals) { foreach ($key_vals as $k = $v) { $path = $ini_array[$heading]; $subsection = explode('.', $k); foreach ($subsection as $ss) $path = $path[$ss]; $path = $v; unset($path); } } $this-ini_array = $ini_array; } David
Re: [PHP] Variable in variable.
On 10-08-26 09:54 AM, João Cândido de Souza Neto wrote: I know that in PHP I can use this: $var1 = text; $var2 = '$var1'; 4cho $$var2; So it gives me text. It would if you didn't have typos and the wrong quotes in the above :) My question is, is there a way of doing it with constant like this? define(CONST, text); $test = CONST; echo $$test; So it gives me text. http://ca3.php.net/manual/en/function.constant.php Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Variable in variable.
Really cool... Thanks and fogive me by my mistake. hehe -- João Cândido de Souza Neto Robert Cummings rob...@interjinn.com escreveu na mensagem news:4c76743a.2060...@interjinn.com... On 10-08-26 09:54 AM, João Cândido de Souza Neto wrote: I know that in PHP I can use this: $var1 = text; $var2 = '$var1'; 4cho $$var2; So it gives me text. It would if you didn't have typos and the wrong quotes in the above :) My question is, is there a way of doing it with constant like this? define(CONST, text); $test = CONST; echo $$test; So it gives me text. http://ca3.php.net/manual/en/function.constant.php Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] constant from variable
Use the constant() function: echo constant( $my . $const ); http://www.php.net/manual/en/function.constant.php -Original Message- From: Tanel Tammik [mailto:keevit...@gmail.com] Sent: Friday, June 04, 2010 3:08 PM To: php-general@lists.php.net Subject: [PHP] constant from variable Hi, define('MYCONST', 'something'); $my = 'my'; $const = 'const'; is it possible to get the value of MYCONST using variables $my and $const_ Br Tanel -- 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] constant from variable
On Fri, 2010-06-04 at 22:07 +0300, Tanel Tammik wrote: Hi, define('MYCONST', 'something'); $my = 'my'; $const = 'const'; is it possible to get the value of MYCONST using variables $my and $const_ Br Tanel I don't really see how you can? The only correlation at all is that the two variables use the same letters combined as their values as the name of the constant but in a different case. Variables and constants in PHP are case-sensitive. Why are you trying to do this anyway? Perhaps there's a better way than what you are trying to do. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Re: Class variable value lost
On Wed, 2009-09-09 at 10:36 -0500, Shawn McKenzie wrote: Sumit Sharma wrote: Hi, I have developed a listing site which is totally class based. Now when it authenticates a user login and set appropriate class variables to true and set user info in user class variables, value of all the set variables are lost when I forward the user to members page. When I check the the value on other page it is set to the default value of the class. Please help. Regard, Sumit You needs to pass the object to the next page. Look into sessions. -- Thanks! -Shawn http://www.spidean.com The object only exists for that instance of the script, so when the user navigates to the next page, the object is freed up from the memory. There are a couple of ways you could get round this: * don't navigate away from the page, and use AJAX calls to update parts of the page for the user (bad imho, as it relies on Javascript) * use sessions like Shawn recommended If you use sessions, you can store the objects themselves as variables into the session. You should be careful with this, as you may not want too many sessions open with large objects in them as, depending on your server setup, sessions could last quite a while, and there may also be a limit on the amount of memory reserved for sessions. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Class variable value lost
On Wed, Sep 9, 2009 at 11:58 AM, Sumit Sharma sumitp...@gmail.com wrote: What I have done is declared one User class in a separate file and created its object there only. After this included this file in all other file which are using its object. So the object is creating only once and included in every other file only once. Now when I over write its variable it value get lost when I send the user in other file. The confusion is if I have created only one object of a class and used the same object through out the site how its value can get lost and I think this is a separate issue than setting $_SESSION variables. This happens because your object is destroyed as soon as PHP finishes serving the request. That's the way the web was designed. If you want your object to persist from one request to another, YOU have to persist it. There are lots of ways to do that. Storing your object in a $_SESSION variable is one of those ways. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Class variable value lost
On Wed, Sep 9, 2009 at 12:58 PM, Sumit Sharma sumitp...@gmail.com wrote: What I have done is declared one User class in a separate file and created its object there only. After this included this file in all other file which are using its object. So the object is creating only once and included in every other file only once. Now when I over write its variable it value get lost when I send the user in other file. The confusion is if I have created only one object of a class and used the same object through out the site how its value can get lost and I think this is a separate issue than setting $_SESSION variables. -- Forwarded message -- From: Ashley Sheridan a...@ashleysheridan.co.uk Date: Wed, Sep 9, 2009 at 9:14 PM Subject: Re: [PHP] Re: Class variable value lost To: Shawn McKenzie nos...@mckenzies.net Cc: Sumit Sharma sumitp...@gmail.com, PHP General Mailing List php-general@lists.php.net On Wed, 2009-09-09 at 10:36 -0500, Shawn McKenzie wrote: Sumit Sharma wrote: Hi, I have developed a listing site which is totally class based. Now when it authenticates a user login and set appropriate class variables to true and set user info in user class variables, value of all the set variables are lost when I forward the user to members page. When I check the the value on other page it is set to the default value of the class. Please help. Regard, Sumit You needs to pass the object to the next page. Look into sessions. -- Thanks! -Shawn http://www.spidean.com The object only exists for that instance of the script, so when the user navigates to the next page, the object is freed up from the memory. There are a couple of ways you could get round this: * don't navigate away from the page, and use AJAX calls to update parts of the page for the user (bad imho, as it relies on Javascript) * use sessions like Shawn recommended If you use sessions, you can store the objects themselves as variables into the session. You should be careful with this, as you may not want too many sessions open with large objects in them as, depending on your server setup, sessions could last quite a while, and there may also be a limit on the amount of memory reserved for sessions. Thanks, Ash http://www.ashleysheridan.co.uk Unless you store the object state your application will not be able to remember it. There is a design pattern specially designed for this, the Memento Pattern ( http://en.wikipedia.org/wiki/Memento_pattern) There are many ways to persist an object: sessions, xml, text files, databases. Pick the one that fits better and you'll be fine. -- Martin Scotta
Re: [PHP] Re: Class variable value lost
The object only exists for that instance of the script, so when the user navigates to the next page, the object is freed up from the memory. There are a couple of ways you could get round this: * don't navigate away from the page, and use AJAX calls to update parts of the page for the user (bad imho, as it relies on Javascript) I think any AJAX-based approached would run into the same difficulty, because each AJAX call is a separate HTTP request from the one that originally loaded the page (and from every other AJAX call). Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] check a variable after EACH function
On Tue, Jun 30, 2009 at 06:31:54PM -0500, Flint Million wrote: This might seem silly but here's what I'm trying to do Suppose I have some kind of check variable - say for example $abort_now. Or it could be a function. Something to be evaluated to a value. I want to execute a block of statements, but after EACH statement executes, check the value of $abort_now and if it is true, break; out of the block. Here's an example do { do_something(); do_something_else(); do_another_thing(); do_yet_another_thing(); and_keep_doing_things(); } while ($abort_now != 1); What I want to happen is for each statement to execute, and keep looping around, until the $abort_now variable is set to 1. Now, suppose any one of the statements in that block may cause $abort_now to become 1. If that happens, I want the block to stop executing immediately and not continue executing further statements. For example, do_another_thing() causes $abort_now to equal 1. I do not want do_yet_another_thing or keep doing things to execute. I want the loop to stop right there. The only way I can think of doing it is to insert a check after each statement: do { do_something(); if ($abort_now == 1) { break; } do_something_else(); if ($abort_now == 1) { break; } do_another_thing(); if ($abort_now == 1) { break; } do_yet_another_thing(); if ($abort_now == 1) { break; } and_keep_doing_things(); if ($abort_now == 1) { break; } } while (TRUE); This might work for 2 or 3 statements but imagine a block of say 15 statements. Having a check after each one would look ugly, and cause trouble if the condition needed to be changed or if I instead decided to check it, say, against a function. So is this possible to do with built in code? or am I stuck with having to put a check after each statement in? Aside from Shawn's exception method, you're relatively limited in how you do this. All the other methods amount to essentially what you're doing here. There's no other loop structure in PHP that will do it any better than what you've devised. FWIW, I've had to do this exact thing with regard to form validation, except I'm not looping. Check each condition, and if it fails, never mind validating the rest of the fields. If you're concerned about the possibility of having to replace the $abort_now variable with a function later, you have two choices. First, use an editor which does search-and-replace efficiently. Second, set up a function which is called wherever you have $abort_now currently. For the moment, have that function simply check the $abort_now variable. In the future, you could have it do something else, but not have to change your existing code. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] check a variable after EACH function
On Jun 30, 2009, at 10:48 PM, Paul M Foster pa...@quillandmouse.com wrote: On Tue, Jun 30, 2009 at 06:31:54PM -0500, Flint Million wrote: This might seem silly but here's what I'm trying to do Suppose I have some kind of check variable - say for example $abort_now. Or it could be a function. Something to be evaluated to a value. I want to execute a block of statements, but after EACH statement executes, check the value of $abort_now and if it is true, break; out of the block. Here's an example do { do_something(); do_something_else(); do_another_thing(); do_yet_another_thing(); and_keep_doing_things(); } while ($abort_now != 1); What I want to happen is for each statement to execute, and keep looping around, until the $abort_now variable is set to 1. Now, suppose any one of the statements in that block may cause $abort_now to become 1. If that happens, I want the block to stop executing immediately and not continue executing further statements. For example, do_another_thing() causes $abort_now to equal 1. I do not want do_yet_another_thing or keep doing things to execute. I want the loop to stop right there. The only way I can think of doing it is to insert a check after each statement: do { do_something(); if ($abort_now == 1) { break; } do_something_else(); if ($abort_now == 1) { break; } do_another_thing(); if ($abort_now == 1) { break; } do_yet_another_thing(); if ($abort_now == 1) { break; } and_keep_doing_things(); if ($abort_now == 1) { break; } } while (TRUE); This might work for 2 or 3 statements but imagine a block of say 15 statements. Having a check after each one would look ugly, and cause trouble if the condition needed to be changed or if I instead decided to check it, say, against a function. So is this possible to do with built in code? or am I stuck with having to put a check after each statement in? Aside from Shawn's exception method, you're relatively limited in how you do this. All the other methods amount to essentially what you're doing here. There's no other loop structure in PHP that will do it any better than what you've devised. FWIW, I've had to do this exact thing with regard to form validation, except I'm not looping. Check each condition, and if it fails, never mind validating the rest of the fields. Isn't that a little rough on the user? Wouldn't a better user experience be to check all the fields and report all errors back to the user in one pass, rather than after each element that fails? If you're concerned about the possibility of having to replace the $abort_now variable with a function later, you have two choices. First, use an editor which does search-and-replace efficiently. Second, set up a function which is called wherever you have $abort_now currently. For the moment, have that function simply check the $abort_now variable. In the future, you could have it do something else, but not have to change your existing code. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Bastien Sent from my iPod -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] check a variable after EACH function
On Tue, Jun 30, 2009 at 11:21:03PM -0400, Phpster wrote: On Jun 30, 2009, at 10:48 PM, Paul M Foster pa...@quillandmouse.com wrote: snip FWIW, I've had to do this exact thing with regard to form validation, except I'm not looping. Check each condition, and if it fails, never mind validating the rest of the fields. Isn't that a little rough on the user? Wouldn't a better user experience be to check all the fields and report all errors back to the user in one pass, rather than after each element that fails? blush Well, yes. Early on I tended to do it this way, but I made my error handling more sophisticated over time. Actually, where I do something like this now is on some blog software I wrote. There are numerous fields to be filled out, and if all are filled out correctly, it updates a database and dumps some files to disk. At each field check, I increment an error count variable if the user screws up. And before I check each field, I check the error count. If there are errors, then I may not update the database and dump the files, so there's no point in checking the contents of certain fields. For example, if the user didn't provide a title for the post, I'm not going to go through the process of XSS checking on their post content, since I'm not going to store it until they give me a title. I'll report to them on the missing fields, though, and allow them to repair. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Hi Guys! Well I tried the INNER JOIN and still can not get it to echo the AdminID so I know it isn't working, (what kind of things should I think about that could make it not work) so far the only query that did work and return the AdminID was my original I believe it was referred to as hosed query, yet then it was explained to me that query while picking up the AdminID was then returning all the rows from workorders anyways because I needed the INNER JOIN, so since that isn't working, I'm thinking my best and fastest route ( I have until Monday on this project and this is just one bit of it OUCH) is to use my hosed query then somehow use the resulting AdminID to fetch the orders from the workorders table, question is , would that be a sub query, or do I just make the query results for AdminID a variable to use in another query? Thanks guys and ps. I'm a she not a he, funny that coders are primarily always assumed to be guys...lol Facebook Me: http://www.facebook.com/profile.php?id=1542024891ref=name Terion On Wed, Jan 28, 2009 at 7:39 PM, Shawn McKenzie nos...@mckenzies.netwrote: Chris wrote: The main problem is that you've never explained what you want to get from the query. The replies have used your code as an example and I'm pretty sure that's not what you want. Unless I totally mis-understand what you want, you have 2 options: 1. Use the 2 queries that I gave you in a previous post. 2. Use a subquery: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); 3 - fix the join ;) Yes, however, I'm going out on a limb here because we don't really know what he wants - he is only getting admin.AdminID, workorders.AdminID returned in all of the queries I've seen. I'm assuming that he wants some of the workorder details. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Terion Miller wrote: Hi Guys! Well I tried the INNER JOIN and still can not get it to echo the AdminID so I know it isn't working, (what kind of things should I think about that could make it not work) so far the only query that did work and return the AdminID was my original I believe it was referred to as hosed query, yet then it was explained to me that query while picking up the AdminID was then returning all the rows from workorders anyways because I needed the INNER JOIN, so since that isn't working, I'm thinking my best and fastest route ( I have until Monday on this project and this is just one bit of it OUCH) is to use my hosed query then somehow use the resulting AdminID to fetch the orders from the workorders table, question is , would that be a sub query, or do I just make the query results for AdminID a variable to use in another query? Thanks guys and ps. I'm a she not a he, funny that coders are primarily always assumed to be guys...lol Facebook Me: http://www.facebook.com/profile.php?id=1542024891ref=name http://www.facebook.com/profile.php?id=1542024891ref=name So the subquery that I gave you doesn't work? Run it and then do a print_r($row); and post what you get. -Shawn Terion On Wed, Jan 28, 2009 at 7:39 PM, Shawn McKenzie nos...@mckenzies.net mailto:nos...@mckenzies.net wrote: Chris wrote: The main problem is that you've never explained what you want to get from the query. The replies have used your code as an example and I'm pretty sure that's not what you want. Unless I totally mis-understand what you want, you have 2 options: 1. Use the 2 queries that I gave you in a previous post. 2. Use a subquery: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); 3 - fix the join ;) Yes, however, I'm going out on a limb here because we don't really know what he wants - he is only getting admin.AdminID, workorders.AdminID returned in all of the queries I've seen. I'm assuming that he wants some of the workorder details. -- Thanks! -Shawn http://www.spidean.com -- 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] Making a Variable from different tables with Matching Dbfields?
Hi Again Here is the query and code I tried: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); $result2 = mysql_query ($sql); $row2 = mysql_fetch_assoc ($result2); $printrow = print_r($row2); Here is my print variables--- Nothing printed with the print_r: $sqlSELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = 'tmiller')$result2Resource id #6$row2$printrow1 So the subquery that I gave you doesn't work? Run it and then do a print_r($row); and post what you get. -Shawn Terion On Wed, Jan 28, 2009 at 7:39 PM, Shawn McKenzie nos...@mckenzies.net mailto:nos...@mckenzies.net wrote: Chris wrote: The main problem is that you've never explained what you want to get from the query. The replies have used your code as an example and I'm pretty sure that's not what you want. Unless I totally mis-understand what you want, you have 2 options: 1. Use the 2 queries that I gave you in a previous post. 2. Use a subquery: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); 3 - fix the join ;) Yes, however, I'm going out on a limb here because we don't really know what he wants - he is only getting admin.AdminID, workorders.AdminID returned in all of the queries I've seen. I'm assuming that he wants some of the workorder details. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Terion Miller wrote: Hi Again Here is the query and code I tried: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); $result2 = mysql_query ($sql); $row2 = mysql_fetch_assoc ($result2); $printrow = print_r($row2); Here is my print variables--- Nothing printed with the print_r: $sql SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = 'tmiller') $result2 Resource id #6 $row2 $printrow 1 O.K., easy: 1. There is no UserName in admin that = $_SESSION['user'] 2. Or, the AdminID that is returned for $_SESSION['user'] is not present in workorders That's why I suggested the 2 query approach the first time so that you could echo out the AdminID after the first query and then go into the db and make sure it exists in workorders. Or, if none were returned, then echo out $_SESSION['user'] and make sure it exists in admin. -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Well upon looking it was number 2, I had no orders in the workorder table, but here is an oddity I wonder if someone can explain if I run this simple query: $query = SELECT * FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; It returns adminID = 7 (my number is 20) username= tmiller (this is correct) it's the only query I can get to return anything but it's the wrong adminID can someone explain what can be making that happen On Thu, Jan 29, 2009 at 2:48 PM, Shawn McKenzie nos...@mckenzies.netwrote: Terion Miller wrote: Hi Again Here is the query and code I tried: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); $result2 = mysql_query ($sql); $row2 = mysql_fetch_assoc ($result2); $printrow = print_r($row2); Here is my print variables--- Nothing printed with the print_r: $sql SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = 'tmiller') $result2 Resource id #6 $row2 $printrow 1 O.K., easy: 1. There is no UserName in admin that = $_SESSION['user'] 2. Or, the AdminID that is returned for $_SESSION['user'] is not present in workorders That's why I suggested the 2 query approach the first time so that you could echo out the AdminID after the first query and then go into the db and make sure it exists in workorders. Or, if none were returned, then echo out $_SESSION['user'] and make sure it exists in admin. -Shawn
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Terion Miller wrote: Well upon looking it was number 2, I had no orders in the workorder table, but here is an oddity I wonder if someone can explain if I run this simple query: $query = SELECT * FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; It returns adminID = 7 (my number is 20) username= tmiller (this is correct) it's the only query I can get to return anything but it's the wrong adminID can someone explain what can be making that happen You cannot return related values from 2 tables without joining the tables in the query which we've shown is not going to work because you need to get AdminID from admin before you can join it to workorders. What your query says is, give me all fields for all rows from admin, where UserName = the session user, and give me the same number of rows from workorders arbitrarily or just the first however many rows. I would be willing to bet that the first record in workorders has AdminID = 7. This works, obviously: $query = SELECT * FROM admin WHERE admin.UserName = '.$_SESSION['user'].' ; -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Shawn McKenzie wrote: Terion Miller wrote: Well upon looking it was number 2, I had no orders in the workorder table, but here is an oddity I wonder if someone can explain if I run this simple query: $query = SELECT * FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; It returns adminID = 7 (my number is 20) username= tmiller (this is correct) it's the only query I can get to return anything but it's the wrong adminID can someone explain what can be making that happen You cannot return related values from 2 tables without joining the tables in the query which we've shown is not going to work because you need to get AdminID from admin before you can join it to workorders. What your query says is, give me all fields for all rows from admin, where UserName = the session user, and give me the same number of rows from workorders arbitrarily or just the first however many rows. I would be willing to bet that the first record in workorders has AdminID = 7. This works, obviously: $query = SELECT * FROM admin WHERE admin.UserName = '.$_SESSION['user'].' ; I also bet that now that you know there are no valid records for your query in the workorders table, that the join queries that others have provided will work great! -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Db fields?
On Wed, Jan 28, 2009 at 3:18 PM, Terion Miller webdev.ter...@gmail.com wrote: Not sure if I'm wording this right, what I am trying to do is look in two tables, match the ID to use to pull information Here's my code but it's not right, although it is picking up the user from the session, I will also post what my variable debugging lists: $query = SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; if ($row['ViewMyOrders'] == NO) { header (Location: Welcome.php?AdminID=$AdminIDmsg=Sorry, you do not have access to that page.); } *Also tried this to pull just this persons orders:* $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID ; $result = mysql_query ($sql); Thanks for looking, t. Your first version gives you a Cartesian product containing more rows than you are expecting. (All rows from the workorders table joined with the row in the admin table where the username matches.) The second version returns all rows where the AdminIDs match, but for all users. You need to combine them: $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID AND admin.UserName = ' . mysql_real_escape_string($username) . '; Although I believe the preferred syntax (at least, I think it's the preferred) is $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Db fields?
Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol On Wed, Jan 28, 2009 at 2:26 PM, Andrew Ballard aball...@gmail.com wrote: On Wed, Jan 28, 2009 at 3:18 PM, Terion Miller webdev.ter...@gmail.com wrote: Not sure if I'm wording this right, what I am trying to do is look in two tables, match the ID to use to pull information Here's my code but it's not right, although it is picking up the user from the session, I will also post what my variable debugging lists: $query = SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; if ($row['ViewMyOrders'] == NO) { header (Location: Welcome.php?AdminID=$AdminIDmsg=Sorry, you do not have access to that page.); } *Also tried this to pull just this persons orders:* $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID ; $result = mysql_query ($sql); Thanks for looking, t. Your first version gives you a Cartesian product containing more rows than you are expecting. (All rows from the workorders table joined with the row in the admin table where the username matches.) The second version returns all rows where the AdminIDs match, but for all users. You need to combine them: $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID AND admin.UserName = ' . mysql_real_escape_string($username) . '; Although I believe the preferred syntax (at least, I think it's the preferred) is $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew
Re: [PHP] Making a Variable from different tables with Matching Db fields?
Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol Because there is ambiguity w/r/t the columns you are selecting, you'll need to use aliases. http://dev.mysql.com/doc/refman/5.1/en/identifiers.html In your code, when you are referencing the column, do so using the alias. That should solve your problem. thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Db fields?
I just read it 3 times and I don't understand it. On Wed, Jan 28, 2009 at 3:22 PM, Christoph Boget christoph.bo...@gmail.comwrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol Because there is ambiguity w/r/t the columns you are selecting, you'll need to use aliases. http://dev.mysql.com/doc/refman/5.1/en/identifiers.html In your code, when you are referencing the column, do so using the alias. That should solve your problem. thnx, Christoph
Re: [PHP] Making a Variable from different tables with Matching Db fields?
On Wed, Jan 28, 2009 at 4:22 PM, Christoph Boget christoph.bo...@gmail.com wrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol Because there is ambiguity w/r/t the columns you are selecting, you'll need to use aliases. http://dev.mysql.com/doc/refman/5.1/en/identifiers.html In your code, when you are referencing the column, do so using the alias. That should solve your problem. thnx, Christoph You're right about the ambiguity. I didn't even pay attention to his SELECT list. Actually, though, in this case aliases aren't even necessary. Since workorders.AdminID and admin.AdminID are going to be the same value since that's a join condition, so the OP really only needs to choose one and use it. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Db fields?
On Wed, Jan 28, 2009 at 4:31 PM, Terion Miller webdev.ter...@gmail.com wrote: On Wed, Jan 28, 2009 at 3:22 PM, Christoph Boget christoph.bo...@gmail.com wrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol Because there is ambiguity w/r/t the columns you are selecting, you'll need to use aliases. http://dev.mysql.com/doc/refman/5.1/en/identifiers.html In your code, when you are referencing the column, do so using the alias. That should solve your problem. thnx, Christoph I just read it 3 times and I don't understand it. Try this... (just make sure to assign a valid $username value.) $sql = SELECT workorders.WorkOrderID , workorders.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Db fields?
Terion Miller wrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol On Wed, Jan 28, 2009 at 2:26 PM, Andrew Ballard aball...@gmail.com wrote: On Wed, Jan 28, 2009 at 3:18 PM, Terion Miller webdev.ter...@gmail.com wrote: Not sure if I'm wording this right, what I am trying to do is look in two tables, match the ID to use to pull information Here's my code but it's not right, although it is picking up the user from the session, I will also post what my variable debugging lists: $query = SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; if ($row['ViewMyOrders'] == NO) { header (Location: Welcome.php?AdminID=$AdminIDmsg=Sorry, you do not have access to that page.); } *Also tried this to pull just this persons orders:* $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID ; $result = mysql_query ($sql); Thanks for looking, t. Your first version gives you a Cartesian product containing more rows than you are expecting. (All rows from the workorders table joined with the row in the admin table where the username matches.) The second version returns all rows where the AdminIDs match, but for all users. You need to combine them: $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID AND admin.UserName = ' . mysql_real_escape_string($username) . '; Although I believe the preferred syntax (at least, I think it's the preferred) is $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew I think I see what you're trying to do: $query = SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '; $result = mysql_query($query); $admins = mysql_fetch_assoc($result); $query = SELECT * FROM workorders WHERE AdminID = ' . $admins['AdminID'] . '; $result = mysql_query($query); $workorders = mysql_fetch_assoc($result); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Db fields?
Because there is ambiguity w/r/t the columns you are selecting, you'll need to use aliases. http://dev.mysql.com/doc/refman/5.1/en/identifiers.html In your code, when you are referencing the column, do so using the alias. That should solve your problem. I just read it 3 times and I don't understand it. Try this... (just make sure to assign a valid $username value.) $sql = SELECT workorders.WorkOrderID , workorders.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew is right. If you use the above query, that will probably get you going. But in general, aliases allow you to reference a column as something other than what it is named in the table's schema. It would allow you to do something along the lines of: SELECT Employee.Name AS EmployeeName, Employer.Name AS EmployerName FROM blah blah blah. In the above example, the column Name is ambiguous. By defining an alias, it removes the ambiguity and allows mysql to return the value of both columns. In your code, you would just reference it using: $rowData['EmployeeName'] $rowData['EmployerName'] I hope that helps explain aliases a bit. thnx, Christoph -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Shawn McKenzie wrote: Terion Miller wrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol On Wed, Jan 28, 2009 at 2:26 PM, Andrew Ballard aball...@gmail.com wrote: On Wed, Jan 28, 2009 at 3:18 PM, Terion Miller webdev.ter...@gmail.com wrote: Not sure if I'm wording this right, what I am trying to do is look in two tables, match the ID to use to pull information Here's my code but it's not right, although it is picking up the user from the session, I will also post what my variable debugging lists: $query = SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; if ($row['ViewMyOrders'] == NO) { header (Location: Welcome.php?AdminID=$AdminIDmsg=Sorry, you do not have access to that page.); } *Also tried this to pull just this persons orders:* $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID ; $result = mysql_query ($sql); Thanks for looking, t. Your first version gives you a Cartesian product containing more rows than you are expecting. (All rows from the workorders table joined with the row in the admin table where the username matches.) The second version returns all rows where the AdminIDs match, but for all users. You need to combine them: $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID AND admin.UserName = ' . mysql_real_escape_string($username) . '; Although I believe the preferred syntax (at least, I think it's the preferred) is $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew I think I see what you're trying to do: $query = SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '; $result = mysql_query($query); $admins = mysql_fetch_assoc($result); $query = SELECT * FROM workorders WHERE AdminID = ' . $admins['AdminID'] . '; $result = mysql_query($query); $workorders = mysql_fetch_assoc($result); Well maybe not. Has anyone noticed that all the proposed selects including the OPs are only returning AdminID and WorkOrderID? But in the OPs code he's trying to use $row['ViewMyOrders']! -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
On Wed, Jan 28, 2009 at 3:43 PM, Shawn McKenzie nos...@mckenzies.netwrote: Shawn McKenzie wrote: Terion Miller wrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol On Wed, Jan 28, 2009 at 2:26 PM, Andrew Ballard aball...@gmail.com wrote: On Wed, Jan 28, 2009 at 3:18 PM, Terion Miller webdev.ter...@gmail.com wrote: Not sure if I'm wording this right, what I am trying to do is look in two tables, match the ID to use to pull information Here's my code but it's not right, although it is picking up the user from the session, I will also post what my variable debugging lists: $query = SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; if ($row['ViewMyOrders'] == NO) { header (Location: Welcome.php?AdminID=$AdminIDmsg=Sorry, you do not have access to that page.); } *Also tried this to pull just this persons orders:* $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID ; $result = mysql_query ($sql); Thanks for looking, t. Your first version gives you a Cartesian product containing more rows than you are expecting. (All rows from the workorders table joined with the row in the admin table where the username matches.) The second version returns all rows where the AdminIDs match, but for all users. You need to combine them: $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID AND admin.UserName = ' . mysql_real_escape_string($username) . '; Although I believe the preferred syntax (at least, I think it's the preferred) is $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew I think I see what you're trying to do: $query = SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '; $result = mysql_query($query); $admins = mysql_fetch_assoc($result); $query = SELECT * FROM workorders WHERE AdminID = ' . $admins['AdminID'] . '; $result = mysql_query($query); $workorders = mysql_fetch_assoc($result); Well maybe not. Has anyone noticed that all the proposed selects including the OPs are only returning AdminID and WorkOrderID? But in the OPs code he's trying to use $row['ViewMyOrders']! -- Thanks! -Shawn http://www.spidean.com I have to get only the work orders associated with the adminID, I get the pages but no orders. and if I print my variables I am grabbing the right adminID but it's not then going and grabbing the work orders with it. I'm not up on the correct phrasing, been doing this about 2 months.
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Terion Miller wrote: On Wed, Jan 28, 2009 at 3:43 PM, Shawn McKenzie nos...@mckenzies.netwrote: Shawn McKenzie wrote: Terion Miller wrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol On Wed, Jan 28, 2009 at 2:26 PM, Andrew Ballard aball...@gmail.com wrote: On Wed, Jan 28, 2009 at 3:18 PM, Terion Miller webdev.ter...@gmail.com wrote: Not sure if I'm wording this right, what I am trying to do is look in two tables, match the ID to use to pull information Here's my code but it's not right, although it is picking up the user from the session, I will also post what my variable debugging lists: $query = SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; if ($row['ViewMyOrders'] == NO) { header (Location: Welcome.php?AdminID=$AdminIDmsg=Sorry, you do not have access to that page.); } *Also tried this to pull just this persons orders:* $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID ; $result = mysql_query ($sql); Thanks for looking, t. Your first version gives you a Cartesian product containing more rows than you are expecting. (All rows from the workorders table joined with the row in the admin table where the username matches.) The second version returns all rows where the AdminIDs match, but for all users. You need to combine them: $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID AND admin.UserName = ' . mysql_real_escape_string($username) . '; Although I believe the preferred syntax (at least, I think it's the preferred) is $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew I think I see what you're trying to do: $query = SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '; $result = mysql_query($query); $admins = mysql_fetch_assoc($result); $query = SELECT * FROM workorders WHERE AdminID = ' . $admins['AdminID'] . '; $result = mysql_query($query); $workorders = mysql_fetch_assoc($result); Well maybe not. Has anyone noticed that all the proposed selects including the OPs are only returning AdminID and WorkOrderID? But in the OPs code he's trying to use $row['ViewMyOrders']! -- Thanks! -Shawn http://www.spidean.com I have to get only the work orders associated with the adminID, I get the pages but no orders. and if I print my variables I am grabbing the right adminID but it's not then going and grabbing the work orders with it. I'm not up on the correct phrasing, been doing this about 2 months. Well, try what I posted (needs some error checking). Where does ViewMyOrders come from? admin table? It would be even easier if you put the AdminID in the SESSION also :-) There also seems to be some design flaws. Why query the database for orders if the user is not allowed to view their orders? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
On Wed, Jan 28, 2009 at 4:00 PM, Shawn McKenzie nos...@mckenzies.netwrote: Terion Miller wrote: On Wed, Jan 28, 2009 at 3:43 PM, Shawn McKenzie nos...@mckenzies.net wrote: Shawn McKenzie wrote: Terion Miller wrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol On Wed, Jan 28, 2009 at 2:26 PM, Andrew Ballard aball...@gmail.com wrote: On Wed, Jan 28, 2009 at 3:18 PM, Terion Miller webdev.ter...@gmail.com wrote: Not sure if I'm wording this right, what I am trying to do is look in two tables, match the ID to use to pull information Here's my code but it's not right, although it is picking up the user from the session, I will also post what my variable debugging lists: $query = SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; if ($row['ViewMyOrders'] == NO) { header (Location: Welcome.php?AdminID=$AdminIDmsg=Sorry, you do not have access to that page.); } *Also tried this to pull just this persons orders:* $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID ; $result = mysql_query ($sql); Thanks for looking, t. Your first version gives you a Cartesian product containing more rows than you are expecting. (All rows from the workorders table joined with the row in the admin table where the username matches.) The second version returns all rows where the AdminIDs match, but for all users. You need to combine them: $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID AND admin.UserName = ' . mysql_real_escape_string($username) . '; Although I believe the preferred syntax (at least, I think it's the preferred) is $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew I think I see what you're trying to do: $query = SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '; $result = mysql_query($query); $admins = mysql_fetch_assoc($result); $query = SELECT * FROM workorders WHERE AdminID = ' . $admins['AdminID'] . '; $result = mysql_query($query); $workorders = mysql_fetch_assoc($result); Well maybe not. Has anyone noticed that all the proposed selects including the OPs are only returning AdminID and WorkOrderID? But in the OPs code he's trying to use $row['ViewMyOrders']! -- Thanks! -Shawn http://www.spidean.com I have to get only the work orders associated with the adminID, I get the pages but no orders. and if I print my variables I am grabbing the right adminID but it's not then going and grabbing the work orders with it. I'm not up on the correct phrasing, been doing this about 2 months. Well, try what I posted (needs some error checking). Where does ViewMyOrders come from? admin table? It would be even easier if you put the AdminID in the SESSION also :-) There also seems to be some design flaws. Why query the database for orders if the user is not allowed to view their orders? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No the user is allowed to view them, or that is what I'm trying to do exactly , now I have it returning some orders but they don't belong to the correct AdminID , I'm getting closer, I appreciate everyone's help in the right direction!! Terion
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
On Wed, Jan 28, 2009 at 4:12 PM, Terion Miller webdev.ter...@gmail.comwrote: On Wed, Jan 28, 2009 at 4:00 PM, Shawn McKenzie nos...@mckenzies.netwrote: Terion Miller wrote: On Wed, Jan 28, 2009 at 3:43 PM, Shawn McKenzie nos...@mckenzies.net wrote: Shawn McKenzie wrote: Terion Miller wrote: Well I'm stuck I have the AdminID but now I can't seem to use it to pull workorders with that AdminID . I couldn't get your block to work Andrew :( I think I'm just not using it right now that I have it...lol On Wed, Jan 28, 2009 at 2:26 PM, Andrew Ballard aball...@gmail.com wrote: On Wed, Jan 28, 2009 at 3:18 PM, Terion Miller webdev.ter...@gmail.com wrote: Not sure if I'm wording this right, what I am trying to do is look in two tables, match the ID to use to pull information Here's my code but it's not right, although it is picking up the user from the session, I will also post what my variable debugging lists: $query = SELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; if ($row['ViewMyOrders'] == NO) { header (Location: Welcome.php?AdminID=$AdminIDmsg=Sorry, you do not have access to that page.); } *Also tried this to pull just this persons orders:* $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID ; $result = mysql_query ($sql); Thanks for looking, t. Your first version gives you a Cartesian product containing more rows than you are expecting. (All rows from the workorders table joined with the row in the admin table where the username matches.) The second version returns all rows where the AdminIDs match, but for all users. You need to combine them: $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID AND admin.UserName = ' . mysql_real_escape_string($username) . '; Although I believe the preferred syntax (at least, I think it's the preferred) is $sql = SELECT workorders.WorkOrderID , workorders.AdminID, admin.AdminID FROM workorders INNER JOIN admin ON workorders.AdminID = admin.AdminID WHERE admin.UserName = ' . mysql_real_escape_string($username) . '; Andrew I think I see what you're trying to do: $query = SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '; $result = mysql_query($query); $admins = mysql_fetch_assoc($result); $query = SELECT * FROM workorders WHERE AdminID = ' . $admins['AdminID'] . '; $result = mysql_query($query); $workorders = mysql_fetch_assoc($result); Well maybe not. Has anyone noticed that all the proposed selects including the OPs are only returning AdminID and WorkOrderID? But in the OPs code he's trying to use $row['ViewMyOrders']! -- Thanks! -Shawn http://www.spidean.com I have to get only the work orders associated with the adminID, I get the pages but no orders. and if I print my variables I am grabbing the right adminID but it's not then going and grabbing the work orders with it. I'm not up on the correct phrasing, been doing this about 2 months. Well, try what I posted (needs some error checking). Where does ViewMyOrders come from? admin table? It would be even easier if you put the AdminID in the SESSION also :-) There also seems to be some design flaws. Why query the database for orders if the user is not allowed to view their orders? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No the user is allowed to view them, or that is what I'm trying to do exactly , now I have it returning some orders but they don't belong to the correct AdminID , I'm getting closer, I appreciate everyone's help in the right direction!! Terion Here are my variables when I reveal them, I am picking up the right adminID I can't figure out why it's returning random orders though: $querySELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = 'tmiller' $resultResource id #5$rowkeyvalue[WorkOrderID] 44[AdminID]7$SortByWorkOrderID DESC$Page2$PerPage30$StartPage30 $sqlSELECT workorders.WorkOrderID, workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID $Total3
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Here are my variables when I reveal them, I am picking up the right adminID I can't figure out why it's returning random orders though: $querySELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = 'tmiller' $result Resource id #5 $row key value [WorkOrderID] 44 [AdminID] 7 $SortBy WorkOrderID DESC $Page 2 $PerPage 30 $StartPage30 $sql SELECT workorders.WorkOrderID, workorders.AdminID, admin.AdminID FROM workorders, admin WHERE workorders.AdminID = admin.AdminID $Total3 Because your queries are hosed. You want to populate $row with what? If you want all the fields in workorders, then this works great: SELECT * FROM workorders WHERE AdminID = 7 -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Here are my variables when I reveal them, I am picking up the right adminID I can't figure out why it's returning random orders though: $querySELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = 'tmiller' Please please please trim your posts to relevant stuff. I had to go through 4 pages of previous attempts to try and find what you posted. Trim it down to what you need to post. It's picking random stuff because you're not joining the tables properly. You have: select admin.AdminID, workorers.AdminID from admin, workorders WHERE admin.userName='tmiller'; You haven't told the db how to join the two tables together, so it's doing a cross or cartesian join (useful in some cases, but not here). What that means is for each row in 'admin', it will show every row in 'workorders' and vice versa. What you want is to only show rows that match up: select admin.AdminID, workorers.AdminID from admin inner join workorders using (AdminID) WHERE admin.userName='tmiller'; which means for every row in admin, make sure there is a matching row (based on the adminid) in workorders. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
I'm not sure what you mean by trim the posts, please explain so I can spare folks from redundant text. Your post made perfect sense to me about the INNER JOIN , I looked it up but it is not returning the AdminID, maybe my syntax is wrong? $query = SELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders ON AdminID(admin, workorders) WHERE admin.UserName = '.$_SESSION['user'].' ; $result = mysql_query ($query); $row = mysql_fetch_assoc ($result); echo $row['AdminID']; thanks again!! terion On Wed, Jan 28, 2009 at 4:28 PM, Chris dmag...@gmail.com wrote: Here are my variables when I reveal them, I am picking up the right adminID I can't figure out why it's returning random orders though: $querySELECT admin.AdminID, workorders.AdminID FROM admin, workorders WHERE admin.UserName = 'tmiller' Please please please trim your posts to relevant stuff. I had to go through 4 pages of previous attempts to try and find what you posted. Trim it down to what you need to post. It's picking random stuff because you're not joining the tables properly. You have: select admin.AdminID, workorers.AdminID from admin, workorders WHERE admin.userName='tmiller'; You haven't told the db how to join the two tables together, so it's doing a cross or cartesian join (useful in some cases, but not here). What that means is for each row in 'admin', it will show every row in 'workorders' and vice versa. What you want is to only show rows that match up: select admin.AdminID, workorers.AdminID from admin inner join workorders using (AdminID) WHERE admin.userName='tmiller'; which means for every row in admin, make sure there is a matching row (based on the adminid) in workorders. -- Postgresql php tutorials http://www.designmagick.com/
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Terion Miller wrote: I'm not sure what you mean by trim the posts, please explain so I can spare folks from redundant text. Before you post, remove any text that you're not referencing (in this case I removed my suggestion). Your post made perfect sense to me about the INNER JOIN , I looked it up but it is not returning the AdminID, maybe my syntax is wrong? $query = SELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders ON AdminID(admin, workorders) WHERE admin.UserName = '.$_SESSION['user'].' ; The syntax is wrong. inner join workorders using (adminid) ^^ only works if both tables are using the same field name, the db will expand it into the syntax below. Here you just need to specify the fieldname to join on (ie the common one). or inner join workorders on (admin.adminID=workorders.adminID) ^^ if the field names are not named the same, eg: select * from comments inner join users on (comments.user_id=users.id) You have to use the full tablename (or alias) and the field name. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Your post made perfect sense to me about the INNER JOIN , I looked it up but it is not returning the AdminID, maybe my syntax is wrong? $query = SELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders ON AdminID(admin, workorders) WHERE admin.UserName = '.$_SESSION['user'].' ; The syntax is wrong. inner join workorders using (adminid) ^^ only works if both tables are using the same field name, the db will expand it into the syntax below. Here you just need to specify the fieldname to join on (ie the common one). or inner join workorders on (admin.adminID=workorders.adminID) ^^ if the field names are not named the same, eg: select * from comments inner join users on (comments.user_id=users.id) Well I tried both ways and still cannot get it to pick up the AdminID, $querySELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders on AdminID WHERE admin.UserName = 'tmiller' $result$row $SortByWorkOrderID DESC$Page1$PerPage30$StartPage0$sqlSELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders ON AdminID(admin, workorders) WHERE admin.UserName = 'tmiller' $Total0
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Well I tried both ways and still cannot get it to pick up the AdminID, $query SELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders on AdminID WHERE admin.UserName = 'tmiller' $result $row $SortBy WorkOrderID DESC $Page 1 $PerPage30 $StartPage 0 $sql SELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders ON AdminID(admin, workorders) WHERE admin.UserName = 'tmiller' $Total 0 That is not the right syntax still. It needs to be: select admin.AdminID, workorers.AdminID from admin inner join workorders using (AdminID) WHERE admin.userName='tmiller'; or select admin.AdminID, workorers.AdminID from admin inner join workorders ON (admin.AdminID=workorders.AdminID) WHERE admin.userName='tmiller'; -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Terion Miller wrote: Your post made perfect sense to me about the INNER JOIN , I looked it up but it is not returning the AdminID, maybe my syntax is wrong? $query = SELECT admin.AdminID , workorders.AdminID FROM admin INNER JOIN workorders ON AdminID(admin, workorders) WHERE admin.UserName = '.$_SESSION['user'].' ; The syntax is wrong. inner join workorders using (adminid) ^^ only works if both tables are using the same field name, the db will expand it into the syntax below. Here you just need to specify the fieldname to join on (ie the common one). or inner join workorders on (admin.adminID=workorders.adminID) ^^ if the field names are not named the same, eg: select * from comments inner join users on (comments.user_id=users.id http://users.id) Well I tried both ways and still cannot get it to pick up the AdminID, The main problem is that you've never explained what you want to get from the query. The replies have used your code as an example and I'm pretty sure that's not what you want. Unless I totally mis-understand what you want, you have 2 options: 1. Use the 2 queries that I gave you in a previous post. 2. Use a subquery: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
The main problem is that you've never explained what you want to get from the query. The replies have used your code as an example and I'm pretty sure that's not what you want. Unless I totally mis-understand what you want, you have 2 options: 1. Use the 2 queries that I gave you in a previous post. 2. Use a subquery: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); 3 - fix the join ;) -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Making a Variable from different tables with Matching Dbfields?
Chris wrote: The main problem is that you've never explained what you want to get from the query. The replies have used your code as an example and I'm pretty sure that's not what you want. Unless I totally mis-understand what you want, you have 2 options: 1. Use the 2 queries that I gave you in a previous post. 2. Use a subquery: $sql = SELECT * FROM workorders WHERE AdminID = (SELECT AdminID FROM admin WHERE UserName = ' . mysql_real_escape_string($_SESSION['user']) . '); 3 - fix the join ;) Yes, however, I'm going out on a limb here because we don't really know what he wants - he is only getting admin.AdminID, workorders.AdminID returned in all of the queries I've seen. I'm assuming that he wants some of the workorder details. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Remote File Variable Injection Safety?
2009/1/7 Daniel Kolbo kolb0...@umn.edu: suppose there is a file at http://otherhost.com/remote.php that looks like this: ?php if (!isset($safe_flag)) { die(hacking attempt); } echo You are in; ? Suppose i executed the following php file at http://myhost.com/local.php ?php require_once(http://otherhost.com/remote.php;); ? Is there any way to get local.php to display You are in, by only modifying local.php? That is, is there a way to set $safe_flag on the remote host as one requests a file from the remote host from within local.php? I have genuine, academic, non-belligerent intentions when asking this question. Doing this is evil and should be avoided if at all possible. However, assuming you really need to do it this way... The best way to validate inclusion is to check the value of $_SERVER['REMOTE_ADDR'] in the remote script and only allow known IPs. This is not foolproof but will kill off casual attempts to get the code. Alternatively if you change the test for $safe_flag to $_GET['safe_flag'] and add ?safe_flag=1 to the end of the URL in the require call that should also work, but is easily copied. You could randomise safe_flag and the value to make it more difficult, but checking the IP is far better IMHO. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Remote File Variable Injection Safety?
If register_globals is on (ewww!) at otherhost.com, then ?safe_flag on the URL will get in. This is one of the reasons why register_globals should be OFF. NOTE: The code you gave does not describe the circumstances whereby $safe_flag is set. There could be all manner of other issues around that code that we cannot address without seeing more. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Remote File Variable Injection Safety?
c...@l-i-e.com wrote: If register_globals is on (ewww!) at otherhost.com, then ?safe_flag on the URL will get in. This is one of the reasons why register_globals should be OFF. NOTE: The code you gave does not describe the circumstances whereby $safe_flag is set. There could be all manner of other issues around that code that we cannot address without seeing more. There is no other code. This is an example I created to help me understand finer points of PHP. thanks, dK
Re: [PHP] Passing a variable which is an aggregate function
The Doctor wrote: What I am trying to do is to pass an aggregate variable which is the sum of some smaller variable. This var also need to finish in the form of $.YY . Pointers please. Most of the above can be done using number_format(). The dollar sign you will have to add yourself. http://php.net/number_format -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing a variable which is an aggregate function
On Fri, Oct 10, 2008 at 1:33 PM, The Doctor [EMAIL PROTECTED] wrote: What I am trying to do is to pass an aggregate variable which is the sum of some smaller variable. This var also need to finish in the form of $.YY . Pointers please. Would you care to explain a little further what you are trying to do. I can't tell from your post what you mean by an aggregate variable or the sum of some smaller variable. What are you passing this to/from? Are you looking for something like this? http://www.php.net/manual/en/function.array-sum.php Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing a variable which is an aggregate function
On Fri, Oct 10, 2008 at 01:48:01PM -0400, Andrew Ballard wrote: On Fri, Oct 10, 2008 at 1:33 PM, The Doctor [EMAIL PROTECTED] wrote: What I am trying to do is to pass an aggregate variable which is the sum of some smaller variable. This var also need to finish in the form of $.YY . Pointers please. Would you care to explain a little further what you are trying to do. I can't tell from your post what you mean by an aggregate variable or the sum of some smaller variable. What are you passing this to/from? Are you looking for something like this? http://www.php.net/manual/en/function.array-sum.php Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. Certainly: Here is a relevant sample of the script: form action=https://esqa.moneris.com/HPPDP/index.php; method=post input type=hidden name=ps_store_id value=CL535tore1 input type=hidden name=hpp_key value=hpYHLXQ5G6BY input type=hidden name=charge_total value=$var input type=hidden name=subject value=PD Solutions Order Form input type=hidden name=recipients value=[EMAIL PROTECTED] input type=hidden name=required value=realname,email input type=hidden name=mail_options value=NoEmpty input type=hidden name=title value=PD Solutions Order input type=hidden name=cc_visitor value=1 input type=hidden name=bad_url value=https://secure.nl2k.ab.ca/pdsolutions/; INPUT TYPE=HIDDEN NAME=env_report VALUE=REMOTE_HOST,REMOTE_ADDR TABLE border=0 cellpadding=0 cellspacing=0 width=90% tr bgcolor=#EBEBEB td align=centerfont face=Arial,Helvetica size=2 color=blackstrongItem/strong/tdtdnbsp;/td td align=centerfont face=Arial,Helvetica size=2 color=blackstrongDate Time/strong/td td align=centerfont face=Arial,Helvetica size=2 color=blackstrongQuantity/strong/td td align=centerfont face=Arial,Helvetica size=2 color=blackstrongPrice/strong/td /tr tr td align=leftfont face=Arial,Helvetica size=2Pest Control Products Act/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 27-2008 12.00 Noon/td td align=leftinput value=0 type=text size=2 name=PCPAOCT27/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Sprayer Circuits/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 27-2008 3.00pm/td td align=leftinput value=0 type=text size=2 name=SCOCT27/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=leftfont face=Arial,Helvetica size=2IPM Fundamentals/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 27-2008 6.00pm/td td align=leftinput value=0 type=text size=2 name=IPMOCT27/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Acute Chronic Toxicity/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 27-2008 8.00pm/td td align=leftinput value=0 type=text size=2 name=ACTOCT27/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Developing New Pesticides/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 28-2008 10.00am/td td align=leftinput value=0 type=text size=2 name=DNPOCT28 = $60.00/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Rinsate Management/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 28-2008 12.00 noon/td td align=leftinput value=0 type=text size=2 name=RMOCT28/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Developing an Environmental Plan/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 28-2008 3.00pm/td td align=leftinput value=0 type=text size=2 name=DEPOCT28/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Sprayer Calibration/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 28-2008 7.00pm/td td align=leftinput value=0 type=text size=2 name=SCOCT28/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Provincial Pesticide Legislation/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 29-2008 10.00am/td td align=leftinput value=0 type=text size=2 name=PPLOCT29/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Perception of Risk/td/atdnbsp;/td td align=leftfont face=Arial,Helvetica size=2October 29-2008 12.00 noon/td td align=leftinput value=0 type=text size=2 name=POROCT29/td td align=rightfont face=Arial,Helvetica size=2$60.00/td/tr trtd align=left font face=Arial,Helvetica size=2Environmental Monitoring/td/atdnbsp;/td
Re: [PHP] Static method variable
Quoting Christoph Boget [EMAIL PROTECTED]: Perhaps I'm misunderstanding what a static method variable is supposed to do. I thought the value would be static for an class' instance but it appears it is static across all instances of the class. Consider: class StaticTest { public function __construct() { } public function test( $newVal ) { static $retval = ''; if( $retval == '' ) { $retval = $newVal; } echo $retval . 'br'; } } $one = new StaticTest(); $one-test( 'joe' ); $two = new StaticTest(); $two-test( 'bob' ); Should it be working that way? thnx, Chris That's exactly how a static class var functions. It's available cross all instances of the class. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Static method variable
If you're looking for a persistent variable in one class instance, then you need a member variable. If you want it persistent across all class instances, you want a static variable. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Christoph Boget wrote: Perhaps I'm misunderstanding what a static method variable is supposed to do. I thought the value would be static for an class' instance but it appears it is static across all instances of the class. Consider: class StaticTest { public function __construct() { } public function test( $newVal ) { static $retval = ''; if( $retval == '' ) { $retval = $newVal; } echo $retval . 'br'; } } $one = new StaticTest(); $one-test( 'joe' ); $two = new StaticTest(); $two-test( 'bob' ); Should it be working that way? thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Static method variable
Christoph Boget schreef: Perhaps I'm misunderstanding what a static method variable is supposed to do. I thought the value would be static for an class' instance but it appears it is static across all instances of the class. Consider: class StaticTest { public function __construct() { } public function test( $newVal ) { static $retval = ''; if( $retval == '' ) { $retval = $newVal; } echo $retval . 'br'; } } $one = new StaticTest(); $one-test( 'joe' ); $two = new StaticTest(); $two-test( 'bob' ); Should it be working that way? yes. it's a function variable that retains state. everyone misread your opst so far ... this has nothing to do with static class scope, although it does work in the same way. you can do the exact same thing with a normal function: function test( $newVal ) { static $retval; if(!isset($retval)) $retval = $newVal; echo $retval . \n; } test('joe'); test('bob'); thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
Frames?! As a fellow Wisconsinite and a web developer, I'm going to have to ask you to leave the state. Minnesota can have you. :P Jay PS - No, but seriously, frames?!?! There's nothing wrong with a Frame every once in a while! Granted they aren't used much anymore, but sometimes they can be useful!
RE: [PHP] Re: Passing variable to a page in a frameset
-Original Message- From: Dan Shirah [mailto:[EMAIL PROTECTED] Sent: Friday, August 15, 2008 9:20 AM To: Jay Moore Cc: php-general@lists.php.net Subject: Re: [PHP] Re: Passing variable to a page in a frameset Frames?! As a fellow Wisconsinite and a web developer, I'm going to have to ask you to leave the state. Minnesota can have you. :P Jay PS - No, but seriously, frames?!?! There's nothing wrong with a Frame every once in a while! Granted they aren't used much anymore, but sometimes they can be useful! I believe frames and framesets are being phased out of XHTML altogether. It's all about DIVs nowadays. I think there's an XHTML specification for something like frames, but it's just as ugly. Todd Boyd Web Programmer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
On Aug 15, 2008, at 9:20 AM, Dan Shirah wrote: Frames?! As a fellow Wisconsinite and a web developer, I'm going to have to ask you to leave the state. Minnesota can have you. :P Jay PS - No, but seriously, frames?!?! There's nothing wrong with a Frame every once in a while! Granted they aren't used much anymore, but sometimes they can be useful! I know, I know. I'm not a fan of frames either, and have never even thought of using them until now. The problem is, our library catalog is on a different server and provides results for a consortium of 30 libraries. So, what we've been doing is including a search box for the catalog on web pages. Which works fine, but it's easy for people to get caught up in the catalog with no good way to get back to the site you came from. So, I created a frame page that has a small button in the top frame that takes you back to where you came from. So, the site itself isn't using frames, only when you search the catalog. Of course, that's if I can get it working... - jody -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Passing variable to a page in a frameset
Actually you may want to check back with basic html at the target parameter on your search form statement. HTH, Warren Vail Vail Systems Technology [EMAIL PROTECTED] -Original Message- From: Jay Moore [mailto:[EMAIL PROTECTED] Sent: Friday, August 15, 2008 7:03 AM To: php-general@lists.php.net Subject: [PHP] Re: Passing variable to a page in a frameset Jody Cleveland wrote: Hello, I've got a website here: http://beta.menashalibrary.org/about On every page, i've got a search box at the top. This search box searches the library's web catalog. The problem is, when someone searches, it takes them away from the site. What I'd like to do is take what a person searches for, and load it into the bottom frame of this page: http://beta.menashalibrary.org/sites/beta.menashalibrary.org/themes/sa lamander/searchframe.html Is there a way, with php, to take what someone puts in the search box and put the results into the bottom frame of a frameset when the originating page does not contain frames? - jody Frames?! As a fellow Wisconsinite and a web developer, I'm going to have to ask you to leave the state. Minnesota can have you. :P Jay PS - No, but seriously, frames?!?! -- 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] Re: Passing variable to a page in a frameset
On Aug 15, 2008, at 1:22 PM, Warren Vail wrote: Actually you may want to check back with basic html at the target parameter on your search form statement. HTH, Warren Vail Vail Systems Technology [EMAIL PROTECTED] Target won't work for me because the originating page with the search box is not part of any frameset. I'm trying to get the search results from that page to go to a page that is part of a frameset. - jody -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
On 15 Aug 2008, at 19:39, Jody Cleveland wrote: On Aug 15, 2008, at 1:22 PM, Warren Vail wrote: Actually you may want to check back with basic html at the target parameter on your search form statement. HTH, Warren Vail Vail Systems Technology [EMAIL PROTECTED] Target won't work for me because the originating page with the search box is not part of any frameset. I'm trying to get the search results from that page to go to a page that is part of a frameset. Are you saying that the frame you want to have the search results shown in doesn't exist when the search form is submitted? If it does then it doesn't matter where the form is, just specify the target as the name of the frame and it will almost certainly work. If however you want the search to create the frameset when it runs then you have a completely different problem which is best solved using some sort of session. The script that handles the POST will need to store the details of the search somewhere and output the frameset. The frame that needs to contain the results would then grab the details and run the search outputting the results. If I'm completely misunderstanding you please feel free to elaborate. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
On Aug 15, 2008, at 1:46 PM, Stut wrote: On 15 Aug 2008, at 19:39, Jody Cleveland wrote: On Aug 15, 2008, at 1:22 PM, Warren Vail wrote: Actually you may want to check back with basic html at the target parameter on your search form statement. HTH, Warren Vail Vail Systems Technology [EMAIL PROTECTED] Target won't work for me because the originating page with the search box is not part of any frameset. I'm trying to get the search results from that page to go to a page that is part of a frameset. Are you saying that the frame you want to have the search results shown in doesn't exist when the search form is submitted? If it does then it doesn't matter where the form is, just specify the target as the name of the frame and it will almost certainly work. If however you want the search to create the frameset when it runs then you have a completely different problem which is best solved using some sort of session. The script that handles the POST will need to store the details of the search somewhere and output the frameset. The frame that needs to contain the results would then grab the details and run the search outputting the results. That is exactly what I want. I apologize for the confusion. I was having a hard time trying to put what I was trying to do in words. But, yes, your second paragraph is exactly what I want to do. My knowledge of PHP is very limited, and I've tried to search for something that will do this, but couldn't find anything. - jody -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Passing variable to a page in a frameset
Probably something I don't understand about your implementation, but the form parameter will allow a target parameter, and if the frameset contains a frame that is named (even one different from the one that contains the search form), the results should be placed in the target frame. Without a target, if the form is outside the frameset, it will replace the entire frameset, exactly what you describe. Warren -Original Message- From: Jody Cleveland [mailto:[EMAIL PROTECTED] Sent: Friday, August 15, 2008 11:40 AM To: php-general@lists.php.net Subject: Re: [PHP] Re: Passing variable to a page in a frameset On Aug 15, 2008, at 1:22 PM, Warren Vail wrote: Actually you may want to check back with basic html at the target parameter on your search form statement. HTH, Warren Vail Vail Systems Technology [EMAIL PROTECTED] Target won't work for me because the originating page with the search box is not part of any frameset. I'm trying to get the search results from that page to go to a page that is part of a frameset. - jody -- 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] Re: Passing variable to a page in a frameset
On 15 Aug 2008, at 19:50, Jody Cleveland wrote: On Aug 15, 2008, at 1:46 PM, Stut wrote: On 15 Aug 2008, at 19:39, Jody Cleveland wrote: On Aug 15, 2008, at 1:22 PM, Warren Vail wrote: Actually you may want to check back with basic html at the target parameter on your search form statement. HTH, Warren Vail Vail Systems Technology [EMAIL PROTECTED] Target won't work for me because the originating page with the search box is not part of any frameset. I'm trying to get the search results from that page to go to a page that is part of a frameset. Are you saying that the frame you want to have the search results shown in doesn't exist when the search form is submitted? If it does then it doesn't matter where the form is, just specify the target as the name of the frame and it will almost certainly work. If however you want the search to create the frameset when it runs then you have a completely different problem which is best solved using some sort of session. The script that handles the POST will need to store the details of the search somewhere and output the frameset. The frame that needs to contain the results would then grab the details and run the search outputting the results. That is exactly what I want. I apologize for the confusion. I was having a hard time trying to put what I was trying to do in words. But, yes, your second paragraph is exactly what I want to do. My knowledge of PHP is very limited, and I've tried to search for something that will do this, but couldn't find anything. Ok, then I have to ask the question... why frames? If you really need frames then you need to come up with a way to pass the search from the script the search form loads to the specific frame in the frameset it outputs. You could do this through a GET parameter, or via a session or in several other ways. In any case you'd be far better off not using frames if possible, so why frames? -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
That is exactly what I want. I apologize for the confusion. I was having a hard time trying to put what I was trying to do in words. But, yes, your second paragraph is exactly what I want to do. My knowledge of PHP is very limited, and I've tried to search for something that will do this, but couldn't find anything. - jody In that case, I would not use frames at all. I believe in the top frame all you wanted to store was the search text, right? Just have your search link do something like this: html head script language=JavaScript !-- function submitForm() { document.search_form.action=' http://beta.menashalibrary.org/sites/beta.menashalibrary.org/themes/salamander/searchframe.html '; document.search_form.submit(); } //-- /script /head body form name=search_form method=post action= input type=text name=search_name value= a href=javascript:submitForm()SEARCH/a /form /body /html And then on http://beta.menashalibrary.org/sites/beta.menashalibrary.org/themes/salamander/searchframe.html just assign your posted search value and make a hidden form field. html head body ?php $searched_text = $_POST['search_name']; ? form name=my_search method=post action= input type=hidden name=search_text value=$searched_text table width='800' border='0' align='center' cellpadding='2' cellspacing='2' bordercolor='#00' tr td?php echo You searched for: .$searched_text; ?/td /tr /table /form /body /html
Re: [PHP] Re: Passing variable to a page in a frameset
On Aug 15, 2008, at 2:05 PM, Stut wrote: On 15 Aug 2008, at 19:50, Jody Cleveland wrote: On Aug 15, 2008, at 1:46 PM, Stut wrote: On 15 Aug 2008, at 19:39, Jody Cleveland wrote: On Aug 15, 2008, at 1:22 PM, Warren Vail wrote: Actually you may want to check back with basic html at the target parameter on your search form statement. HTH, Warren Vail Vail Systems Technology [EMAIL PROTECTED] Target won't work for me because the originating page with the search box is not part of any frameset. I'm trying to get the search results from that page to go to a page that is part of a frameset. Are you saying that the frame you want to have the search results shown in doesn't exist when the search form is submitted? If it does then it doesn't matter where the form is, just specify the target as the name of the frame and it will almost certainly work. If however you want the search to create the frameset when it runs then you have a completely different problem which is best solved using some sort of session. The script that handles the POST will need to store the details of the search somewhere and output the frameset. The frame that needs to contain the results would then grab the details and run the search outputting the results. That is exactly what I want. I apologize for the confusion. I was having a hard time trying to put what I was trying to do in words. But, yes, your second paragraph is exactly what I want to do. My knowledge of PHP is very limited, and I've tried to search for something that will do this, but couldn't find anything. Ok, then I have to ask the question... why frames? If you really need frames then you need to come up with a way to pass the search from the script the search form loads to the specific frame in the frameset it outputs. You could do this through a GET parameter, or via a session or in several other ways. In any case you'd be far better off not using frames if possible, so why frames? I work for a consortium of 30 libraries. Each library has their own website, but they all share the same web catalog. On each library's website there is a search box to search the catalog, which is on a completely different server from the websites. We've been finding that once people use that search box, they get distracted with the catalog and have no easy way to get back to the library's website. The problem I was tasked with is, coming up with a way to search the catalog with an easy way to return to where the user was before they initiated the search. The only way I thought to do this was to use a frameset for the search results. Which, you can see here: http://beta.menashalibrary.org/sites/beta.menashalibrary.org/themes/salamander/searchframe.html If anyone has any ideas, other than using frames for the results, I'd love to hear them. The problem is, there's nothing I can do on the web catalog end. - jody -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
On 15 Aug 2008, at 20:21, Jody Cleveland wrote: I work for a consortium of 30 libraries. Each library has their own website, but they all share the same web catalog. On each library's website there is a search box to search the catalog, which is on a completely different server from the websites. We've been finding that once people use that search box, they get distracted with the catalog and have no easy way to get back to the library's website. The problem I was tasked with is, coming up with a way to search the catalog with an easy way to return to where the user was before they initiated the search. The only way I thought to do this was to use a frameset for the search results. Which, you can see here: http://beta.menashalibrary.org/sites/beta.menashalibrary.org/themes/salamander/searchframe.html Is POST the only way to get the search results, or will it work with a GET? If GET will work then you need to set the search form to post to a script on your site which then outputs a frameset with a URL on your server that shows the header, and the URL for the shared search server with all the POSTed variables as GET parameters as the second frame. Job done. If not then you're going to need to play silly wotsits with a hidden form in the top frame which reposts the search to the bottom form. Not pretty and would require JS but it should work. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
On Aug 15, 2008, at 2:27 PM, Stut wrote: On 15 Aug 2008, at 20:21, Jody Cleveland wrote: I work for a consortium of 30 libraries. Each library has their own website, but they all share the same web catalog. On each library's website there is a search box to search the catalog, which is on a completely different server from the websites. We've been finding that once people use that search box, they get distracted with the catalog and have no easy way to get back to the library's website. The problem I was tasked with is, coming up with a way to search the catalog with an easy way to return to where the user was before they initiated the search. The only way I thought to do this was to use a frameset for the search results. Which, you can see here: http://beta.menashalibrary.org/sites/beta.menashalibrary.org/themes/salamander/searchframe.html Is POST the only way to get the search results, or will it work with a GET? If GET will work then you need to set the search form to post to a script on your site which then outputs a frameset with a URL on your server that shows the header, and the URL for the shared search server with all the POSTed variables as GET parameters as the second frame. Job done. GET should work too. Do you know of any examples anywhere online for this? My brain shuts off at the thought of how I'd do that. - jody -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
I work for a consortium of 30 libraries. Each library has their own website, but they all share the same web catalog. On each library's website there is a search box to search the catalog, which is on a completely different server from the websites. We've been finding that once people use that search box, they get distracted with the catalog and have no easy way to get back to the library's website. The problem I was tasked with is, coming up with a way to search the catalog with an easy way to return to where the user was before they initiated the search. The only way I thought to do this was to use a frameset for the search results. Which, you can see here: http://beta.menashalibrary.org/sites/beta.menashalibrary.org/themes/salamander/searchframe.html If anyone has any ideas, other than using frames for the results, I'd love to hear them. The problem is, there's nothing I can do on the web catalog end. - jody Easiest solution - Open the search page in a new window. Then they can just close it to get back to the previous window... I now understand what you're trying to say in regards to the frames. The top frame resides completely on your server so you can place a Go back to homepage link to direct people back to YOUR libraries homepage. And the bottom frame contains the search results page that you have no control over and cannot alter to simply place a Home link on it. And that should remain since the global search results page is accessed by multiple libraries. Like I said above, the easiest thing to do is just open it in a seperate window so they can close it at any time and still be at the same place on your libraries website.
Re: [PHP] Re: Passing variable to a page in a frameset
On 15 Aug 2008, at 20:34, Jody Cleveland wrote: On Aug 15, 2008, at 2:27 PM, Stut wrote: On 15 Aug 2008, at 20:21, Jody Cleveland wrote: I work for a consortium of 30 libraries. Each library has their own website, but they all share the same web catalog. On each library's website there is a search box to search the catalog, which is on a completely different server from the websites. We've been finding that once people use that search box, they get distracted with the catalog and have no easy way to get back to the library's website. The problem I was tasked with is, coming up with a way to search the catalog with an easy way to return to where the user was before they initiated the search. The only way I thought to do this was to use a frameset for the search results. Which, you can see here: http://beta.menashalibrary.org/sites/beta.menashalibrary.org/themes/salamander/searchframe.html Is POST the only way to get the search results, or will it work with a GET? If GET will work then you need to set the search form to post to a script on your site which then outputs a frameset with a URL on your server that shows the header, and the URL for the shared search server with all the POSTed variables as GET parameters as the second frame. Job done. GET should work too. Do you know of any examples anywhere online for this? My brain shuts off at the thought of how I'd do that. Off the top of my head and very untested... ?php $vars = array(); foreach ($_POST as $k = $v) { $vars[] = urlencode($k).'='.urlencode($v); } $searchurl = 'http://search.server.com/search.php?'.implode('', $vars); ? frameset frame src=/header.html / frame src=?php echo $searchurl; ? / /frameset Modify to your own frameset/url requirements but that's the basic idea. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Passing variable to a page in a frameset
GET should work too. Do you know of any examples anywhere online for this? My brain shuts off at the thought of how I'd do that. - jody When you GET a value you are retrieving a passed value that appears in the address bar: Example http://www.mysite.com?name=joe www.mysite.com is the website ?name=joe is the value being passed by GET To put this value into a PHP variable you would simply do: ?php $name = $_GET['name']; ? http://www.google.com/search?hl=enq=encrypt+javascript
Re: [PHP] Re: Passing variable to a page in a frameset
On 8/15/08, Dan Shirah [EMAIL PROTECTED] wrote: GET should work too. Do you know of any examples anywhere online for this? My brain shuts off at the thought of how I'd do that. - jody When you GET a value you are retrieving a passed value that appears in the address bar: Example http://www.mysite.com?name=joe http://www.mysite.com/?name=joe www.mysite.com is the website ?name=joe is the value being passed by GET To put this value into a PHP variable you would simply do: ?php $name = $_GET['name']; ? Although, since you have no control over the actual search page to edit the code and have it pull in the $_GET[''] values you will probably have to disect the search page to get its form elements so you can feed them to it and force a submit. I just looked at your site, and after I input my search criteria and click submit I have to again enter in the search criteria and submit to actually get some results.