Re: [PHP] Re: Conditional compilation
You can always call a function with a DEBUG flag and execute certain parts if it's set or not. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Robert Cummings wrote: On Fri, 2008-08-15 at 18:34 -0500, Shawn McKenzie wrote: Herman Gomez wrote: Hi, Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time: #define debug TRUE #ifdef(debug) //debugging code #endif That way I can include/exclude easily all debugging code in the final compiled code. In PHP I have not been able to find anything like that. The only solution I've found is having this kind of code in every debug code block: if ($debug) { //debugging code } But this means that the debugging code is in the final compiled (interpreted) code, wasting cpu cycles even if there won't be any debugging in production. Does somebody know if there is something like conditional compilation in PHP that I can use? Regards, Herman Gomez Madrid, Spain. Well PHP isn't compiled it's interpreted. Still I don't see much diff and no overhead between the following: #ifdef(debug) //debugging code #endif ---and--- if (defined('DEBUG')) { //debugging code } I don't think checking a define is cpu intensive or even measurable. You could assume that it's defined as true or false and: if (DEBUG === true)) { //debugging code } Still, I don't think that even checking $debug is measurable. That depends on where the conditional exists. In C you can place it anywhere, including wihtin a tight loop. In PHP you end up having to either take an overhead penalty or duplicate code to force the conditional outside of a tight loop. Contrast the following: ?php if( DEBUG === true ) { for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. // Do something dependent on debug mode. } } else { for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. } } ? Versus: ?php for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. if( DEBUG === true ) { // Do something dependent on debug mode. } } ? Now depending on what Do something common between DEBUG and !DEBUG modes does, it can be a real PITA to do code duplication to optimize debug mode handling, but on the other hand, you really don't want to check if DEBUG is enabled 1 million times. If I recall though... a few years ago the answer to this question was that there's no reason why you can't use the C pre-processor to accomplish the same thing with PHP. The down side though is that then you lose debugging information such as the real line number on which an error occurs. Cheers, Rob. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Conditional compilation
Herman Gomez wrote: Hi, Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time: #define debug TRUE #ifdef(debug) //debugging code #endif That way I can include/exclude easily all debugging code in the final compiled code. In PHP I have not been able to find anything like that. The only solution I've found is having this kind of code in every debug code block: if ($debug) { //debugging code } But this means that the debugging code is in the final compiled (interpreted) code, wasting cpu cycles even if there won't be any debugging in production. Does somebody know if there is something like conditional compilation in PHP that I can use? Regards, Herman Gomez Madrid, Spain. Well PHP isn't compiled it's interpreted. Still I don't see much diff and no overhead between the following: #ifdef(debug) //debugging code #endif ---and--- if (defined('DEBUG')) { //debugging code } I don't think checking a define is cpu intensive or even measurable. You could assume that it's defined as true or false and: if (DEBUG === true)) { //debugging code } Still, I don't think that even checking $debug is measurable. -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Conditional compilation
On Fri, 2008-08-15 at 18:34 -0500, Shawn McKenzie wrote: Herman Gomez wrote: Hi, Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time: #define debug TRUE #ifdef(debug) //debugging code #endif That way I can include/exclude easily all debugging code in the final compiled code. In PHP I have not been able to find anything like that. The only solution I've found is having this kind of code in every debug code block: if ($debug) { //debugging code } But this means that the debugging code is in the final compiled (interpreted) code, wasting cpu cycles even if there won't be any debugging in production. Does somebody know if there is something like conditional compilation in PHP that I can use? Regards, Herman Gomez Madrid, Spain. Well PHP isn't compiled it's interpreted. Still I don't see much diff and no overhead between the following: #ifdef(debug) //debugging code #endif ---and--- if (defined('DEBUG')) { //debugging code } I don't think checking a define is cpu intensive or even measurable. You could assume that it's defined as true or false and: if (DEBUG === true)) { //debugging code } Still, I don't think that even checking $debug is measurable. That depends on where the conditional exists. In C you can place it anywhere, including wihtin a tight loop. In PHP you end up having to either take an overhead penalty or duplicate code to force the conditional outside of a tight loop. Contrast the following: ?php if( DEBUG === true ) { for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. // Do something dependent on debug mode. } } else { for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. } } ? Versus: ?php for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. if( DEBUG === true ) { // Do something dependent on debug mode. } } ? Now depending on what Do something common between DEBUG and !DEBUG modes does, it can be a real PITA to do code duplication to optimize debug mode handling, but on the other hand, you really don't want to check if DEBUG is enabled 1 million times. If I recall though... a few years ago the answer to this question was that there's no reason why you can't use the C pre-processor to accomplish the same thing with PHP. The down side though is that then you lose debugging information such as the real line number on which an error occurs. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Conditional compilation
Robert Cummings wrote: On Fri, 2008-08-15 at 18:34 -0500, Shawn McKenzie wrote: Herman Gomez wrote: Hi, Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time: #define debug TRUE #ifdef(debug) //debugging code #endif That way I can include/exclude easily all debugging code in the final compiled code. In PHP I have not been able to find anything like that. The only solution I've found is having this kind of code in every debug code block: if ($debug) { //debugging code } But this means that the debugging code is in the final compiled (interpreted) code, wasting cpu cycles even if there won't be any debugging in production. Does somebody know if there is something like conditional compilation in PHP that I can use? Regards, Herman Gomez Madrid, Spain. Well PHP isn't compiled it's interpreted. Still I don't see much diff and no overhead between the following: #ifdef(debug) //debugging code #endif ---and--- if (defined('DEBUG')) { //debugging code } I don't think checking a define is cpu intensive or even measurable. You could assume that it's defined as true or false and: if (DEBUG === true)) { //debugging code } Still, I don't think that even checking $debug is measurable. That depends on where the conditional exists. In C you can place it anywhere, including wihtin a tight loop. In PHP you end up having to either take an overhead penalty or duplicate code to force the conditional outside of a tight loop. Contrast the following: ?php if( DEBUG === true ) { for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. // Do something dependent on debug mode. } } else { for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. } } ? Versus: ?php for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. if( DEBUG === true ) { // Do something dependent on debug mode. } } ? Now depending on what Do something common between DEBUG and !DEBUG modes does, it can be a real PITA to do code duplication to optimize debug mode handling, but on the other hand, you really don't want to check if DEBUG is enabled 1 million times. If I recall though... a few years ago the answer to this question was that there's no reason why you can't use the C pre-processor to accomplish the same thing with PHP. The down side though is that then you lose debugging information such as the real line number on which an error occurs. Cheers, Rob. Great! Then the answer is: wait, wait, write it in C! -Shawn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Conditional compilation
On Fri, 2008-08-15 at 22:56 -0500, Shawn McKenzie wrote: Robert Cummings wrote: On Fri, 2008-08-15 at 18:34 -0500, Shawn McKenzie wrote: Herman Gomez wrote: Hi, Here is something I used to do in C/C++ to include/exclude automaticaly all debugging code at compiling time: #define debug TRUE #ifdef(debug) //debugging code #endif That way I can include/exclude easily all debugging code in the final compiled code. In PHP I have not been able to find anything like that. The only solution I've found is having this kind of code in every debug code block: if ($debug) { //debugging code } But this means that the debugging code is in the final compiled (interpreted) code, wasting cpu cycles even if there won't be any debugging in production. Does somebody know if there is something like conditional compilation in PHP that I can use? Regards, Herman Gomez Madrid, Spain. Well PHP isn't compiled it's interpreted. Still I don't see much diff and no overhead between the following: #ifdef(debug) //debugging code #endif ---and--- if (defined('DEBUG')) { //debugging code } I don't think checking a define is cpu intensive or even measurable. You could assume that it's defined as true or false and: if (DEBUG === true)) { //debugging code } Still, I don't think that even checking $debug is measurable. That depends on where the conditional exists. In C you can place it anywhere, including wihtin a tight loop. In PHP you end up having to either take an overhead penalty or duplicate code to force the conditional outside of a tight loop. Contrast the following: ?php if( DEBUG === true ) { for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. // Do something dependent on debug mode. } } else { for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. } } ? Versus: ?php for( $i = 0; $i 100; $i++ ) { // Do something common between DEBUG and !DEBUG modes. if( DEBUG === true ) { // Do something dependent on debug mode. } } ? Now depending on what Do something common between DEBUG and !DEBUG modes does, it can be a real PITA to do code duplication to optimize debug mode handling, but on the other hand, you really don't want to check if DEBUG is enabled 1 million times. If I recall though... a few years ago the answer to this question was that there's no reason why you can't use the C pre-processor to accomplish the same thing with PHP. The down side though is that then you lose debugging information such as the real line number on which an error occurs. Cheers, Rob. Great! Then the answer is: wait, wait, write it in C! Well PHP does have a great extension system so you can plug in your own C code ;) Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php conditional loop question
I am running php as a client and I have the script running 24/7 to download the data from the connection. Is there a function to see if the connection drops. ?? is there a way to keep restart the function in the script. perhaps use a while and exit the function with a number exit(3) and use that value as the condition in the while? Randy * Thus wrote Randy L Johnson Jr ([EMAIL PROTECTED]): I have done this but it does not seem to ever get to the end of file, I have it inserting the values into the database, it goes for awhile around 12 to 24 hours and then stops inserting the values into the database and I have to restart the script... ah.. so it sound like the connection is dropping at some point thus your socket becomes not usuable. From my previous post you can use http://php.net/stream_set_timeout btw, any reason why your using pfsocketopen vs. just fsocketopen? the pfsocketopen would be only needed if you plan on using that socket on a different page request. Come to think of it the pfsocketopen might even give you problems even if you use the stream_set_timeout function. HTH, Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php . IncrediMail - Email has finally evolved - Click Here
Re: [PHP] php conditional loop question
* Thus wrote Randy L Johnson Jr ([EMAIL PROTECTED]): I have done this but it does not seem to ever get to the end of file, I have it inserting the values into the database, it goes for awhile around 12 to 24 hours and then stops inserting the values into the database and I have to restart the script... ah.. so it sound like the connection is dropping at some point thus your socket becomes not usuable. From my previous post you can use http://php.net/stream_set_timeout so if your fread comes back with no data you should exit the function. btw, any reason why your using pfsocketopen vs. just fsocketopen? the pfsocketopen would be only needed if you plan on using that socket on a different page request. Come to think of it the pfsocketopen might even give you problems even if you use the stream_set_timeout function. HTH, Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php conditional loop question
* Thus wrote Randy L Johnson Jr ([EMAIL PROTECTED]): I have the program downloading the data and all that so I don't need help with that. I just want to be able to reun the function if the data stops or in more general a certain condition is met. I'm not entirely sure how you are reading the data in from the socket but your condition is when there is no data that came back from the socket. This function might be usefull: http://php.net/stream_set_timeout Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php conditional loop question
I think you need to set the connection to nonblocking mode. Use bool stream_set_blocking ( resource stream, int mode) Then if no data is available for a longer time (it's up to you), you can break out of the loop and do something else. Randy L Johnson Jr wrote: I am running php as a client and I have the script running 24/7 to download the data from the connection. Is there a function to see if the connection drops.?? is there a way to keep restart the function in the script. perhaps use a while and exit the function with a number exit(3) and use that value as the condition in the while? Randy * Thus wrote Randy L Johnson Jr ([EMAIL PROTECTED]): I have done this but it does not seem to ever get to the end of file, I have it inserting the values into the database, it goes for awhile around 12 to 24 hours and then stops inserting the values into the database and I have to restart the script... ah.. so it sound like the connection is dropping at some point thus your socket becomes not usuable. From my previous post you can use http://php.net/stream_set_timeout btw, any reason why your using pfsocketopen vs. just fsocketopen? the pfsocketopen would be only needed if you plan on using that socket on a different page request. Come to think of it the pfsocketopen might even give you problems even if you use the stream_set_timeout function. HTH, Curt -- I used to think I was indecisive, but now I'm not so sure. -- 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] php conditional loop question
On Wed, Aug 13, 2003 at 09:51:39PM -0400, Randy L Johnson Jr wrote: I have a function that makes a connection to a live datafeed website and downloads data via a pfsockopen() statement. After awhile the data stops feeding but the connection stays open. when the data stops I want to exit out of the function and have the function run again Pseudo code... while (1) { pfsockopen(... blah blah ...); while (not end of file) { get the line and do what you want with it... } } --Dan -- FREE scripts that make web and database programming easier http://www.analysisandsolutions.com/software/ T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7th Ave #4AJ, Brooklyn NYv: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php conditional loop question
I have done this but it does not seem to ever get to the end offile, I have it inserting the values into the database, it goes for awhile around 12 to 24 hours and then stops inserting the values into the database and I have to restart the script... Randy ---Original Message--- From: Analysis Solutions Date: Wednesday, August 13, 2003 10:02:15 PM To: PHP List Subject: Re: [PHP] php conditional loop question On Wed, Aug 13, 2003 at 09:51:39PM -0400, Randy L Johnson Jr wrote: I have a function that makes a connection to a live datafeed website and downloads data via a pfsockopen() statement. After awhile the data stops feeding but the connection stays open. when the data stops I want to exit out of the function and have the function run again Pseudo code... while (1) { pfsockopen(... blah blah ...); while (not end of file) { get the line and do what you want with it... } } --Dan -- FREE scripts that make web and database programming easier http://www.analysisandsolutions.com/software/ T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7th Ave #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php . IncrediMail - Email has finally evolved - Click Here
[PHP] php conditional loop question
ok. This is probably simple but I am not thinking straight. Here is what I want to do I have a function that makes a connection to a live datafeed website and downloads data via a pfsockopen() statement. After awhile the data stops feeding but the connection stays open. when the data stops I want to exit out of the function and have the function run again basically i don't know how to exit out of the function and have the program run the function again I have the program downloading the data and all that so I don't need help with that. I just want to be able to reun the function if the data stops or in more general a certain condition is met. any ideas and comments would be greatly appreciated. Randy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php conditional formatting question
I know it's possible, but I just can't get it working. In an old file I have a straight php coding doc where it's used and am now trying to mimic the resulting output. I'm trying to get a result from a query in a specific color when it fits the bill ( if ($teamcaptain == $deelnemer) //if yes, we'll make the result green echo td class=achtergrondbottom; etc (SEE BELOW)) when the person ($deelnemer) also fits the $teamcaptain I want this one to be listed in different format, I dont care if it's only color or if it's a css. Hope there's someone able to help me here, thanks, Martin The Netherlands part of php code: do { ? tr class=laag2 ?php $teamcaptain = strtoupper($row_rsCompetitie['tmcap']);echo $teamcaptain; $deelnemer = strtoupper($row_rsCompetitie['zoekcode']);echo $deelnemer;? ?php if ($teamcaptain == $deelnemer) //if yes, we'll make the result green echo td class=achtergrondbottom; } ? td?php echo $row_rsCompetitie['zoekcode']; ?/td td class=achtergrondgrijs?php echo $row_rsCompetitie['roepnaam']; ?/td td?php echo $row_rsCompetitie['samennaam']; ?/td td?php echo $row_rsCompetitie['handicap']; ?/td td?php echo $row_rsCompetitie['tmnaam']; ?/td td?php echo $row_rsCompetitie['tmklasse']; ?/td td?php echo $row_rsCompetitie['tmpoule']; ?/td /tr ?php } while ($row_rsCompetitie = mysql_fetch_assoc($rsCompetitie)); ? /table -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php conditional formatting question
I'm new to PHP but I had a similar problem. I was comparing information in a flat text file with a variable in my php code. They never matched according to the php. I echo'd both values to the screen and they matched. So then I echo'd them to the screen with three 'a' in front and three 'a' in back of the values. Much to my suspicion there was a blank space behind the value from the text file. So, I used rtrim to get rid of the blank space. Looks something like this: $contents[1] = rtrim($contents[1]); if ($idname = = $contents[0]) { echo Works Thus Far!; exit; } Hope this is helpful! ! ! Roger WMB wrote: I know it's possible, but I just can't get it working. In an old file I have a straight php coding doc where it's used and am now trying to mimic the resulting output. I'm trying to get a result from a query in a specific color when it fits the bill ( if ($teamcaptain == $deelnemer) //if yes, we'll make the result green echo td class=achtergrondbottom; etc (SEE BELOW)) when the person ($deelnemer) also fits the $teamcaptain I want this one to be listed in different format, I dont care if it's only color or if it's a css. Hope there's someone able to help me here, thanks, Martin The Netherlands part of php code: do { ? tr class=laag2 ?php $teamcaptain = strtoupper($row_rsCompetitie['tmcap']);echo $teamcaptain; $deelnemer = strtoupper($row_rsCompetitie['zoekcode']);echo $deelnemer;? ?php if ($teamcaptain == $deelnemer) //if yes, we'll make the result green echo td class=achtergrondbottom; } ? td?php echo $row_rsCompetitie['zoekcode']; ?/td td class=achtergrondgrijs?php echo $row_rsCompetitie['roepnaam']; ?/td td?php echo $row_rsCompetitie['samennaam']; ?/td td?php echo $row_rsCompetitie['handicap']; ?/td td?php echo $row_rsCompetitie['tmnaam']; ?/td td?php echo $row_rsCompetitie['tmklasse']; ?/td td?php echo $row_rsCompetitie['tmpoule']; ?/td /tr ?php } while ($row_rsCompetitie = mysql_fetch_assoc($rsCompetitie)); ? /table -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] if conditional
Hello, I would like to how to know how to create an if conditional with only one condition. Can some one tell me the way to do this. This is my previos code : if (!name) { print Pplease enter your name.; } exit; if (!$email) { print PPlease enter you e-mail } exit; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if conditional
You confused us. Would you like to explain us exactly what you meant? Maybe with mentioning us your reasons/goals. -- Maxim Maletsky [EMAIL PROTECTED] www.PHPBeginner.com // where PHP Begins On Tue, 15 Oct 2002 15:31:14 +0800 Muhammad Khairuzzaman [EMAIL PROTECTED] wrote: Hello, I would like to how to know how to create an if conditional with only one condition. Can some one tell me the way to do this. This is my previos code : if (!name) { print Pplease enter your name.; } exit; if (!$email) { print PPlease enter you e-mail } exit; ? -- 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] if conditional
If the code isn't working, its because you weren't using a $name in the first if statement. Always the little things ! :) But this should work... if (!$name) { print Pplease enter your name.; } if (!$email) { print PPlease enter you e-mail; } Hello, I would like to how to know how to create an if conditional with only one condition. Can some one tell me the way to do this. This is my previos code : if (!name) { print Pplease enter your name.; } exit; if (!$email) { print PPlease enter you e-mail } exit; ? -- 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 Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Logic -- conditional statements
On Tue, Jun 04, 2002 at 04:40:26AM +0400, Ricardo Fitzgerald wrote: I'm trying to echo a neat table I've GOT to bust your chops. That table and your code are anything BUT neat. For neat, you need to put /td tags to close each cell. Also nest your code properly... if ($value2 ==0) { echo td$variable1; } as opposed to if ($value2 ==0) { echo td$variable1; } Now, to the logic problems in your code. Please note, I've snipped a LOT... //Value1 is always 1 if ($value1 == 0) { exit } So, if the value is always 1 why bother even doing the test? if ($value2 ==0) { .td ... $variable1 ... } if($value2 == 0) { .td ... $variable1 ... .tr /next row .td ... $variable5 ... } Dude, you're evaluating if $value2 == 0 twice and thus printing the same stuff twice. if($value3 == 3) { .td ... $variable1 ... .tr /next row .td ... $variable5 ... ./tr .td ... $variable9 ... Now, if $value3 == 3 you're going ahead and printing out variable1 and 5 all over again. Am I correct in assuming that if value3 == 3 all you want to print is variable9 and up? If so, then just print that. --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Logic -- conditional statements
Hi to all, I'm trying to echo a neat table with values from a form, depending on the values it echoes a table with one row with two or with three: Then I have conditional nested statements, to validate these variables and wrote the table with the proper values in each case, the problem is the table is displayed 3 times instead of 1 each time it finds a value TRUE! I need it to display only once, I mean in the first instance the table, has 1 row, the second 2 rows, the third 3 rows, and they are independent. The code is something like: //Value1 is always 1 if ($value1 == 0) { exit } if ($value2 ==0) { echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... } if($value2 == 0) { . . echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... .tr /next row . .td ... $variable5 ... .td ... $variable6... .td ... $variable7 ... .td ... $variable8 ... ./tr . . } if($value3 == 3) { . . echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... .tr /next row . .td ... $variable5 ... .td ... $variable6... .td ... $variable7 ... .td ... $variable8 ... ./tr . . .td ... $variable9 ... .td ... $variable10... .td ... $variable11 ... .td ... $variable12 ... ./tr . . //and then closes the php script, TIA Regards, Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Logic -- conditional statements
The problem here is that you have defined three different variables $value1,$value2,$value3. Keep only one variable (say,$valueChk) that can take values 1,2 or 3. Then check for the condition. And there's another mistake in the script, you are checking ---if ($value2 ==0)--- twice, you probably mean to check for $value1 ==1 (for the first of the $value2 ==0 checks). Once you are through with these changes, your script will work perfectly. And if you feel like improving it you need not repeat the td statements. You can merely append the additional rows depending on the value of the variable you set (say, $valueChk). the following isn't the actual script, but mainly the logic. $table=table if($valueChk==0) exit if($valueChk==1) { //.append the first TRTD statement to $table variable $table .= TRTD ; } if($valueChk==2) { //.append the second TRTD statement to $table variable } if($valueChk==3) { //.append the third TRTD statement to $table variable } //now close the table tag and echo the $table variable you'll get the table with the desired number of rows. -Naintara -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] t]On Behalf Of Ricardo Fitzgerald Sent: Friday, July 10, 2893 3:44 PM To: [EMAIL PROTECTED] Subject: [PHP] Logic -- conditional statements Hi to all, I'm trying to echo a neat table with values from a form, depending on the values it echoes a table with one row with two or with three: Then I have conditional nested statements, to validate these variables and wrote the table with the proper values in each case, the problem is the table is displayed 3 times instead of 1 each time it finds a value TRUE! I need it to display only once, I mean in the first instance the table, has 1 row, the second 2 rows, the third 3 rows, and they are independent. The code is something like: //Value1 is always 1 if ($value1 == 0) { exit } if ($value2 ==0) { echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... } if($value2 == 0) { . . echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... .tr /next row . .td ... $variable5 ... .td ... $variable6... .td ... $variable7 ... .td ... $variable8 ... ./tr . . } if($value3 == 3) { . . echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... .tr /next row . .td ... $variable5 ... .td ... $variable6... .td ... $variable7 ... .td ... $variable8 ... ./tr . . .td ... $variable9 ... .td ... $variable10... .td ... $variable11 ... .td ... $variable12 ... ./tr . . //and then closes the php script, TIA Regards, Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
FW: [PHP] Logic -- conditional statements
One correction, Ricardo for appending the rows, you will have to change the condition //for 1st row if($valueChk = 1 $valueChk = 3) //for 2nd row if($valueChk = 2 $valueChk = 3) //for 3rd row if($valueChk == 3) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] t]On Behalf Of Naintara Jain Sent: Tuesday, June 04, 2002 2:37 PM To: Ricardo Fitzgerald; [EMAIL PROTECTED] Subject: RE: [PHP] Logic -- conditional statements The problem here is that you have defined three different variables $value1,$value2,$value3. Keep only one variable (say,$valueChk) that can take values 1,2 or 3. Then check for the condition. And there's another mistake in the script, you are checking ---if ($value2 ==0)--- twice, you probably mean to check for $value1 ==1 (for the first of the $value2 ==0 checks). Once you are through with these changes, your script will work perfectly. And if you feel like improving it you need not repeat the td statements. You can merely append the additional rows depending on the value of the variable you set (say, $valueChk). the following isn't the actual script, but mainly the logic. $table=table if($valueChk==0) exit if($valueChk==1) { //.append the first TRTD statement to $table variable $table .= TRTD ; } if($valueChk==2) { //.append the second TRTD statement to $table variable } if($valueChk==3) { //.append the third TRTD statement to $table variable } //now close the table tag and echo the $table variable you'll get the table with the desired number of rows. -Naintara -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] t]On Behalf Of Ricardo Fitzgerald Sent: Friday, July 10, 2893 3:44 PM To: [EMAIL PROTECTED] Subject: [PHP] Logic -- conditional statements Hi to all, I'm trying to echo a neat table with values from a form, depending on the values it echoes a table with one row with two or with three: Then I have conditional nested statements, to validate these variables and wrote the table with the proper values in each case, the problem is the table is displayed 3 times instead of 1 each time it finds a value TRUE! I need it to display only once, I mean in the first instance the table, has 1 row, the second 2 rows, the third 3 rows, and they are independent. The code is something like: //Value1 is always 1 if ($value1 == 0) { exit } if ($value2 ==0) { echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... } if($value2 == 0) { . . echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... .tr /next row . .td ... $variable5 ... .td ... $variable6... .td ... $variable7 ... .td ... $variable8 ... ./tr . . } if($value3 == 3) { . . echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... .tr /next row . .td ... $variable5 ... .td ... $variable6... .td ... $variable7 ... .td ... $variable8 ... ./tr . . .td ... $variable9 ... .td ... $variable10... .td ... $variable11 ... .td ... $variable12 ... ./tr . . //and then closes the php script, TIA Regards, Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Logic -- conditional statements
Switches come in handy here... Switch($valueChk) { case 1: do_whatever1(); case 2: do_whatever2(); case 3: do_whatever3(); break; } If the variable is 1, then all three functions will be called. I don't remember what the original question was or if this even applies, but it's a better solution than all of the IFs that was just posted... ---John Holmes... -Original Message- From: Naintara Jain [mailto:[EMAIL PROTECTED]] Sent: Tuesday, June 04, 2002 5:47 PM To: Ricardo Fitzgerald Cc: Php-General@Lists. Php. Net Subject: FW: [PHP] Logic -- conditional statements One correction, Ricardo for appending the rows, you will have to change the condition //for 1st row if($valueChk = 1 $valueChk = 3) //for 2nd row if($valueChk = 2 $valueChk = 3) //for 3rd row if($valueChk == 3) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] t]On Behalf Of Naintara Jain Sent: Tuesday, June 04, 2002 2:37 PM To: Ricardo Fitzgerald; [EMAIL PROTECTED] Subject: RE: [PHP] Logic -- conditional statements The problem here is that you have defined three different variables $value1,$value2,$value3. Keep only one variable (say,$valueChk) that can take values 1,2 or 3. Then check for the condition. And there's another mistake in the script, you are checking ---if ($value2 ==0)--- twice, you probably mean to check for $value1 ==1 (for the first of the $value2 ==0 checks). Once you are through with these changes, your script will work perfectly. And if you feel like improving it you need not repeat the td statements. You can merely append the additional rows depending on the value of the variable you set (say, $valueChk). the following isn't the actual script, but mainly the logic. $table=table if($valueChk==0) exit if($valueChk==1) { //.append the first TRTD statement to $table variable $table .= TRTD ; } if($valueChk==2) { //.append the second TRTD statement to $table variable } if($valueChk==3) { //.append the third TRTD statement to $table variable } //now close the table tag and echo the $table variable you'll get the table with the desired number of rows. -Naintara -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] t]On Behalf Of Ricardo Fitzgerald Sent: Friday, July 10, 2893 3:44 PM To: [EMAIL PROTECTED] Subject: [PHP] Logic -- conditional statements Hi to all, I'm trying to echo a neat table with values from a form, depending on the values it echoes a table with one row with two or with three: Then I have conditional nested statements, to validate these variables and wrote the table with the proper values in each case, the problem is the table is displayed 3 times instead of 1 each time it finds a value TRUE! I need it to display only once, I mean in the first instance the table, has 1 row, the second 2 rows, the third 3 rows, and they are independent. The code is something like: //Value1 is always 1 if ($value1 == 0) { exit } if ($value2 ==0) { echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... } if($value2 == 0) { . . echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... .tr /next row . .td ... $variable5 ... .td ... $variable6... .td ... $variable7 ... .td ... $variable8 ... ./tr . . } if($value3 == 3) { . . echo // echoes the table . . .td ... $variable1 ... .td ... $variable2... .td ... $variable3 ... .td ... $variable4 ... .tr /next row . .td ... $variable5 ... .td ... $variable6... .td ... $variable7 ... .td ... $variable8 ... ./tr . . .td ... $variable9 ... .td ... $variable10... .td ... $variable11 ... .td ... $variable12 ... ./tr . . //and then closes the php script, TIA Regards, Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Conditional include based on virtual host ?
On Fri, 26 Jan 2001 14:52:28 +0100, you wrote: Hello, I have developed a large web application the contents of which (language and data) depends on the URL the site is accessed from, e.g. en.site.com would display the "english" site, and "fr.site.com" would display the french site It's a good way to do it, I wrote an extension to FastTemplates (and the phplib templates.inc) to help with such an event so you could have multiple levels of templates, falling back eventually (and hopefully, or it's broken) to a default set. The defaults could be English (and no-language, others could be fr, es, pt, Klingon, whatever. A different name to access the site could look utterly different, just have most of the same content on the page, in different places. I was going to use it to re-skin websites according to who it was for (originally it was going to be a 'virtual bookshop' that companies could brand for themselves). The whole thing is "parameterized" through a set of global variables (or defines) that reside in a file called settings.php. The question is: how can I include the "right" settings.php file, depending on the virtual host used to access the site? Take a look at the output of phpinfo() for the two virtual sites, especially HTTP_SERVER_VARS["HTTP_HOST"] HTTP_SERVER_VARS["SERVER_NAME"] Server_name is likely to be the 'main name' (www.example.com), but http_host should be the name it's called by (not always the same thing) Alister -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]