Re: [PHP] If Statements Array and Notice Undefined Index
On Thursday, 31 March 2011 at 15:45, Nicholas Cooper wrote: Good day, I have three arrays A, B and C. Anyone of them might not have the 'id' key set which will give the Notice Undefined index: id. I just wanted to know what the correct approach to this problem would be; without making the code overly complicated to read by introducing a number of if isset statements. if ($arrayA['id'] == $arrayB['id'] || $arrayC['id'] == $arrayB['id']) { } I have notices switched off, but I want to know the right way to do this. There's probably a number of different right ways to solve this, how would you do it? This is how I handle this... // Define this function somewhere global function ifsetor($array, $key, $default = null) { return (isset($array[$key]) ? $array[$key] : $default); } if (ifsetor($arrayA, 'id') == ifsetor($arrayB, 'id') || ifsetor($arrayC, 'id') == ifsetor($arrayB, 'id'))... If you need to avoid a match if neither $arrayA nor $arrayB have an id you simply pass a different default for each one. -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] If Statements Array and Notice Undefined Index
On 31 March 2011 15:53, Stuart Dallas stu...@3ft9.com wrote: On Thursday, 31 March 2011 at 15:45, Nicholas Cooper wrote: Good day, I have three arrays A, B and C. Anyone of them might not have the 'id' key set which will give the Notice Undefined index: id. I just wanted to know what the correct approach to this problem would be; without making the code overly complicated to read by introducing a number of if isset statements. if ($arrayA['id'] == $arrayB['id'] || $arrayC['id'] == $arrayB['id']) { } I have notices switched off, but I want to know the right way to do this. There's probably a number of different right ways to solve this, how would you do it? This is how I handle this... // Define this function somewhere global function ifsetor($array, $key, $default = null) { return (isset($array[$key]) ? $array[$key] : $default); } if (ifsetor($arrayA, 'id') == ifsetor($arrayB, 'id') || ifsetor($arrayC, 'id') == ifsetor($arrayB, 'id'))... If you need to avoid a match if neither $arrayA nor $arrayB have an id you simply pass a different default for each one. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ Thank you, that is quiet an elegant solution. Very little additional code excluding the function and it could also easily be extended for multi dimensional arrays by changing $key to an array and looping through each index in turn. Best Regards Nicholas
Re: [PHP] elseif statements
On Tue, 2009-05-05 at 22:31 -0700, Jim Lucas wrote: Well, since nobody seems to want to answer your question, I will... :) It has to do with you using an assignment '=' instead of a comparison '==' operator in your condition. He already found the problem and fixed it :) 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] elseif statements
He already found the problem and fixed it :) Correction: His problem was pointed out to him and he was able to follow instructions he he. I think I posted yesterday, but I had the double= in the script earlier, but it was givning inconsisitant answers, however when I changed the = for== AND changed from calling the information from the $_COOKIE to the variable, it worked as I had hoped. Again, thank you to all for helping. Gary Robert Cummings rob...@interjinn.com wrote in message news:1241606832.610.108.ca...@localhost... On Tue, 2009-05-05 at 22:31 -0700, Jim Lucas wrote: Well, since nobody seems to want to answer your question, I will... :) It has to do with you using an assignment '=' instead of a comparison '==' operator in your condition. He already found the problem and fixed it :) 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] elseif statements
At 2:57 PM -0400 5/4/09, Gary wrote: I am trying to get this to work, however it only reads the second if statement. I get no error messages, but as I change counties, the % stays the same. Can someone enlighten me, or should I be looking at switch statements? Thanks for your help. Gary In my opinion, never use elseif -- I've never used it. I don't see any reason whatsoever to do so. In my opinion, whenever your choices exceed two, use switch. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] elseif statements
On Tue, 2009-05-05 at 09:49 -0400, tedd wrote: At 2:57 PM -0400 5/4/09, Gary wrote: I am trying to get this to work, however it only reads the second if statement. I get no error messages, but as I change counties, the % stays the same. Can someone enlighten me, or should I be looking at switch statements? Thanks for your help. Gary In my opinion, never use elseif -- I've never used it. I don't see any reason whatsoever to do so. In my opinion, whenever your choices exceed two, use switch. That's some of the worst advice I've ever seen. 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] elseif statements
On Tue, 2009-05-05 at 10:05 -0400, Robert Cummings wrote: On Tue, 2009-05-05 at 09:49 -0400, tedd wrote: At 2:57 PM -0400 5/4/09, Gary wrote: I am trying to get this to work, however it only reads the second if statement. I get no error messages, but as I change counties, the % stays the same. Can someone enlighten me, or should I be looking at switch statements? Thanks for your help. Gary In my opinion, never use elseif -- I've never used it. I don't see any reason whatsoever to do so. In my opinion, whenever your choices exceed two, use switch. That's some of the worst advice I've ever seen. Just so we all know why... ?php $values = array( '', 0, null, '0' ); foreach( $values as $value ) { if( $value === '' ) { echo 'If/ElseIf: The empty string'.\n; } else if( $value === 0 ) { echo 'If/ElseIf: The integer 0'.\n; } else if( $value === null ) { echo 'If/ElseIf: The null value'.\n; } else if( $value === '0' ) { echo 'If/ElseIf: The string value 0'.\n; } switch( $value ) { case '': { echo 'Switch/Case: The empty string'.\n; break; } case 0: { echo 'Switch/Case: The integer 0'.\n; break; } case null: { echo 'Switch/Case: The null value'.\n; break; } case '0': { echo 'Switch/Case: The string value 0'.\n; break; } } echo \n; } ? 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] elseif statements
At 10:13 AM -0400 5/5/09, Robert Cummings wrote: On Tue, 2009-05-05 at 10:05 -0400, Robert Cummings wrote: On Tue, 2009-05-05 at 09:49 -0400, tedd wrote: At 2:57 PM -0400 5/4/09, Gary wrote: I am trying to get this to work, however it only reads the second if statement. I get no error messages, but as I change counties, the % stays the same. Can someone enlighten me, or should I be looking at switch statements? Thanks for your help. Gary In my opinion, never use elseif -- I've never used it. I don't see any reason whatsoever to do so. In my opinion, whenever your choices exceed two, use switch. That's some of the worst advice I've ever seen. Just so we all know why... Yep -- just so we know why: http://php1.net/a/if-v-switch/ It all depends upon how you use the tools at your command. My preference is still valid and I think the code is more readable. YMMV. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] elseif statements
On Tue, 2009-05-05 at 11:21 -0400, tedd wrote: At 10:13 AM -0400 5/5/09, Robert Cummings wrote: On Tue, 2009-05-05 at 10:05 -0400, Robert Cummings wrote: On Tue, 2009-05-05 at 09:49 -0400, tedd wrote: At 2:57 PM -0400 5/4/09, Gary wrote: I am trying to get this to work, however it only reads the second if statement. I get no error messages, but as I change counties, the % stays the same. Can someone enlighten me, or should I be looking at switch statements? Thanks for your help. Gary In my opinion, never use elseif -- I've never used it. I don't see any reason whatsoever to do so. In my opinion, whenever your choices exceed two, use switch. That's some of the worst advice I've ever seen. Just so we all know why... Yep -- just so we know why: http://php1.net/a/if-v-switch/ It all depends upon how you use the tools at your command. My preference is still valid and I think the code is more readable. YMMV. Extra level of indentation, needing to add a break statement for every case. Yours is more verbose and less clear. Forgetting a break statement would lead to a silent bug. Abuse of the switch statement... switching on a constant is not a switch at all. I consider it obfuscated. The techniques you've used are also non-portable to most other languages with a switch construct. Sorry, your attempt to call this good advice fails. 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] elseif statements
2009/5/5 tedd tedd.sperl...@gmail.com: At 10:13 AM -0400 5/5/09, Robert Cummings wrote: On Tue, 2009-05-05 at 10:05 -0400, Robert Cummings wrote: On Tue, 2009-05-05 at 09:49 -0400, tedd wrote: At 2:57 PM -0400 5/4/09, Gary wrote: I am trying to get this to work, however it only reads the second if statement. I get no error messages, but as I change counties, the % stays the same. Can someone enlighten me, or should I be looking at switch statements? Thanks for your help. Gary In my opinion, never use elseif -- I've never used it. I don't see any reason whatsoever to do so. In my opinion, whenever your choices exceed two, use switch. That's some of the worst advice I've ever seen. Just so we all know why... Yep -- just so we know why: http://php1.net/a/if-v-switch/ It all depends upon how you use the tools at your command. My preference is still valid and I think the code is more readable. YMMV. Elseif statements are not solely used to check *one* variable. So in some situations you can't even use a switch without implementing if/else statements inside the switch. BTW: EX1: if ( $value === '0' ) { echo 'If/ElseIf: The string value 0'.br; } EX3: case $value === '' : { echo 'Switch/Case: The empty string'.br; break; } Where is the basic difference in readability? Ah yes, the case is missing the brackets ..make it kinda hard to read for me. .-) Regards Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.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] elseif statements
At 11:29 AM -0400 5/5/09, Robert Cummings wrote: On Tue, 2009-05-05 at 11:21 -0400, tedd wrote: At 10:13 AM -0400 5/5/09, Robert Cummings wrote: Just so we all know why... Yep -- just so we know why: http://php1.net/a/if-v-switch/ It all depends upon how you use the tools at your command. My preference is still valid and I think the code is more readable. YMMV. Extra level of indentation, needing to add a break statement for every case. Yours is more verbose and less clear. Forgetting a break statement would lead to a silent bug. Abuse of the switch statement... switching on a constant is not a switch at all. I consider it obfuscated. The techniques you've used are also non-portable to most other languages with a switch construct. Sorry, your attempt to call this good advice fails. Cheers, Rob. Rob: I agree that the way I use the switch in my example does not port to other languages, but I'm not working in other languages and it's the way I solve my elseif problem in this language. If I was working in a different language, then I would solve it differently. But I have never used an elseif statement, nor do I intend. If you will read my original post, I preference each statement with In my opinion. I can certainly have an opinion about the way I choose to program, can't I? And, what's wrong with voicing that opinion providing that you are stating it as your opinion? While I see what you are doing and agree that your solution is probably better for the majority than mine, your solution still doesn't work for me. I find it confusing and I find my solution much more readable and understandable. Others may find it so as well. As the say in Perl, there is always more than one way to do anything. I admit that you are a better php programmer than I, and I usually learn from you, but on this point I can't follow. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] elseif statements
On Tue, 2009-05-05 at 12:12 -0400, tedd wrote: At 11:29 AM -0400 5/5/09, Robert Cummings wrote: On Tue, 2009-05-05 at 11:21 -0400, tedd wrote: At 10:13 AM -0400 5/5/09, Robert Cummings wrote: Just so we all know why... Yep -- just so we know why: http://php1.net/a/if-v-switch/ It all depends upon how you use the tools at your command. My preference is still valid and I think the code is more readable. YMMV. Extra level of indentation, needing to add a break statement for every case. Yours is more verbose and less clear. Forgetting a break statement would lead to a silent bug. Abuse of the switch statement... switching on a constant is not a switch at all. I consider it obfuscated. The techniques you've used are also non-portable to most other languages with a switch construct. Sorry, your attempt to call this good advice fails. Cheers, Rob. Rob: I agree that the way I use the switch in my example does not port to other languages, but I'm not working in other languages and it's the way I solve my elseif problem in this language. If I was working in a different language, then I would solve it differently. But I have never used an elseif statement, nor do I intend. It may be true that you are not using different languages, but without a compelling argument for one form over another, one should generally take the most general form that is understood and practiced by the majority. You have not made a compelling argument for subverting usual semantics to contort the logic into your vision. If you will read my original post, I preference each statement with In my opinion. I can certainly have an opinion about the way I choose to program, can't I? And, what's wrong with voicing that opinion providing that you are stating it as your opinion? Your opinion is one thing... and this is indeed opinion, but you entangled it with prescription: In my opinion, whenever your choices exceed two, use switch. You are certainly permitted your opinion, as I am too. I am offering my opinion that your advice is bunk... and I have followed it up with argument to back my stated views. While I see what you are doing and agree that your solution is probably better for the majority than mine, your solution still doesn't work for me. I find it confusing and I find my solution much more readable and understandable. Others may find it so as well. As the say in Perl, there is always more than one way to do anything. This is certainly true, when you program for yourself, and you will be the only maintainer of that code. But down the road it is quite likely someone else will view that code and think to themself... WTF! And that makes it a poor judgement call. Anyone can write Perl, but how many can write Perl that a newbie can understand? I admit that you are a better php programmer than I, and I usually learn from you, but on this point I can't follow. I'm not looking for gratification... merely hoping to ensure that readers of your niche style understand that it is niche, and that it is not really the best option of all available options. You are welcome to disagree, your opinion is your own, but as you have argued, we are all entitled to our opinion. Those opinions with the greatest merit should have the better supporting arguments (one would hope anyways :) 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] elseif statements
On 5/5/09 9:49 AM, tedd tedd.sperl...@gmail.com wrote: In my opinion, whenever your choices exceed two, use switch. ick! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] elseif statements
On Tue, May 05, 2009 at 12:12:33PM -0400, tedd wrote: At 11:29 AM -0400 5/5/09, Robert Cummings wrote: On Tue, 2009-05-05 at 11:21 -0400, tedd wrote: At 10:13 AM -0400 5/5/09, Robert Cummings wrote: Just so we all know why... Yep -- just so we know why: http://php1.net/a/if-v-switch/ It all depends upon how you use the tools at your command. My preference is still valid and I think the code is more readable. YMMV. Extra level of indentation, needing to add a break statement for every case. Yours is more verbose and less clear. Forgetting a break statement would lead to a silent bug. Abuse of the switch statement... switching on a constant is not a switch at all. I consider it obfuscated. The techniques you've used are also non-portable to most other languages with a switch construct. Sorry, your attempt to call this good advice fails. I hate to dogpile on Tedd, who's probably a better coder than I, but I'll disagree on two points: 1. I have no problems with the execution or readability of elseif. In fact, I'm grateful for it, since some languages don't have it. 2. I consider Tedd's use of the switch/case construct an abuse. The list has seen this debate before, and Tedd's way of doing it is *legal*. But in my opinion, the variable which switch tests should be the only one tested, as: switch ($var) { case 'alfa': ... break; case 'bravo': ... break; } not: switch (true) { case $var1 == 'alfa': ... break; case $var2 == 'bravo': ... break; } I also appreciate the argument about doing it as it's done in other languages. Tedd's right, this isn't those other languages. But when you code in other languages as well as PHP, doing it the same way in all of them really helps. The lack of semicolon line endings in Python drives me nuts. Perhaps worse, Python has no switch/case construct. For some reason van Rossum eschewed this in favor of if/else/elif. Ugh. Ultimately, it's Tedd's choice, and if the code works, it works. I just wouldn't do it that way. I agree with Robert-- if I saw code like this I had to maintain, I'd be slightly miffed. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] elseif statements
At 12:48 PM -0400 5/5/09, Robert Cummings wrote: I'm not looking for gratification... merely hoping to ensure that readers of your niche style understand that it is niche, and that it is not really the best option of all available options. You are welcome to disagree, your opinion is your own, but as you have argued, we are all entitled to our opinion. Those opinions with the greatest merit should have the better supporting arguments (one would hope anyways :) Cheers, Rob. Rob: Gratification or not -- the point holds true. On this, you make a better argument than I. While I can't follow, I do concede. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] elseif statements
At 1:11 PM -0400 5/5/09, Paul M Foster wrote: I hate to dogpile on Tedd, ... No problem. Some days you're the windshield and some days you're the bug. Hey, I've been wrong before -- I'm used to it. But in my defense, I've always had major problems understanding long ifelse's. You see, I'm dyslexic and I can not follow those long constructs (i.e., more than two decisions). I've always been able to work around the problem. Sure the way php allows switch(true) is very opportunistic for me, but it's legal. I've seen a lot worse, not that my practicing such grants me permission to do so. But I don't seriously think that anyone who reviews my code would be confused as to what I was doing using a switch in such fashion. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] elseif statements
Well, since nobody seems to want to answer your question, I will... :) It has to do with you using an assignment '=' instead of a comparison '==' operator in your condition. Follow along with my inline notes below. Gary wrote: I am trying to get this to work, however it only reads the second if statement. I get no error messages, but as I change counties, the % stays the same. Can someone enlighten me, or should I be looking at switch statements? Thanks for your help. Gary ?php $_SESSION['sale_session']=$_POST['sale']; $_SESSION['assess_session']=$_POST['assess']; $_SESSION['county_session']=$_POST['county']; // checks if bot if ($_POST['address'] != '' ){ exit(Changed field); } $sale_value=$_POST['sale']; $assess_value=$_POST['assess']; $county=$_POST['county']; $chester_ratio=.51; $montco_ratio=.53; $delco_ratio=.58; /*$ratio=.51; /*$correct_assess=($sale_value)*($ratio); this is now the assessment should be */ $chester_correct_assess=($sale_value)*($chester_ratio); $montco_correct_assess=($sale_value)*($montco_ratio); $delco_correct_assess=($sale_value)*($delco_ratio); $chester_assess_difference=($assess_value)-($chester_correct_assess); $montco_assess_difference=($assess_value)-($montco_correct_assess); $delco_assess_difference=($assess_value)-($delco_correct_assess); /* $assess_difference=($assess_value)-($sale_value * $ratio); $percent_difference=($assess_difference)/($assess_value);*/ $chester_percent_difference=($chester_assess_difference)/($assess_value); $delco_percent_difference=($delco_assess_difference)/($assess_value); $montco_percent_difference=($montco_assess_difference)/($assess_value); $chester_percent_savings=($chester_percent_difference)*100; $delco_percent_savings=($delco_percent_difference)*100; $montco_percent_savings=($montco_percent_difference)*100; if(($_COOKIE['county_cookie'] ='Chester') ($chester_assess_difference =5)) The previous line should be, notice the missing == comparison ??? if(($_COOKIE['county_cookie'] == 'Chester') ($chester_assess_difference = 5)) { echo 'h2 style=margin:0;color:#ff;Yes, Your property appears to qualify!/h2br /br /'; echo You 1 believe your home would today sell for b $.number_format($sale_value). /bbr /; echo Your current tax assessment isb $.number_format($assess_value)./bbr /; echo You live in b$county /bbr /; echo Your potential savings could beb .number_format($chester_percent_savings,0).%/bbr /br /; echo According to preliminary calculations based on the information you have entered, you may enjoy a savings of b .number_format($chester_percent_savings,0).% /boff a combined total of county, school and township real estate taxes. Actual dollar amount savings will differ depending on the township that the property is located. Please contact my office for a more precise estimate of savings.br /; } elseif(($_COOKIE['county_cookie']='Delaware') ($delco_assess_difference =3)) { Same thing here echo 'h2 style=margin:0;color:#ff;Yes, Your property appears to qualify!/h2br /br /'; echo You 2 believe your home would today sell for b $.number_format($sale_value). /bbr /; echo Your current tax assessment isb $.number_format($assess_value)./bbr /; echo You live in b$county /bbr /; echo Your potential savings could beb .number_format($delco_percent_savings,0).%/bbr /br /; echo According to preliminary calculations based on the information you have entered, you may enjoy a savings of b .number_format($delco_percent_savings,0).% /boff a combined total of county, school and township real estate taxes. Actual dollar amount savings will differ depending on the township that the property is located. Please contact my office for a more precise estimate of savings.br /; } elseif(($_COOKIE['county_cookie']='Montgomery') ($montco_assess_difference =5)) Same thing here { echo 'h2 style=margin:0;color:#ff;Yes, Your property appears to qualify!/h2br /br /'; echo You 3 believe your home would today sell for b $.number_format($sale_value). /bbr /; echo Your current tax assessment isb $.number_format($assess_value)./bbr /; echo You live in b$county /bbr /; echo Your potential savings could beb .number_format($montco_percent_savings,0).%/bbr /br /; echo According to preliminary calculations based on the information you have entered, you may enjoy a savings of b .number_format($montco_percent_savings,0).% /boff a combined total of county, school and township real estate taxes. Actual dollar amount savings will differ depending on the township that the property is located. Please contact my office for a more precise estimate of savings.br /; } else if(($chester_assess_difference =5) ($chester_assess_difference=1000)) { echo 'h3 style=margin:0;While it appears you may enjoy some savings, the dollar amount may not reach the threshold required for action. If property values in your area continue to decline, you may wish to revisit
Re: [PHP] Prepared statements
Curt Zirzow wrote: On Mon, Mar 06, 2006 at 10:03:10PM +0100, Julius Hacker wrote: Curt Zirzow wrote: I assume your loop is something like: while(condition) { $auction_parts['id'] = 'some value'; $auction_parts['name'] = 'some value'; ... $insert-execute(); } Yes, thats it. My first guess would be, if not aleady done, initialize $auction_parts before you do your bind_param() with something like: $auction_parts = array('id' = null, 'name' = null, ...); $insert-bind_param(issdsis, $auction_house[id], ...); Unfortunately it helps nothing :-( Ok, i didn't really think it would but might have shown a obvious bug with mysqli. According to your original post it was odd that the update prepared statment didn't complain about a NULL value, but the insert did, and it does seem to be related to bind_param and prepare. What are your versions of: php? mysql_client php is built with? mysql server you are connecting to? I've alread a solution, just forgot to post here :) Anthony gave me the hint as he sent me a list of the datatypes accepted by bind_param and so I checked the datatypes of the variables and have seen that $auction_house[id] was a string and not an integer. After I converted it to an integer, it works properly. I don't know exactly why it worked if I did bind_param in the loop but I think it's because it saw there that I gave him a string and converted it automatically to integer. -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
Anthony Ettinger wrote: On 3/6/06, Anthony Ettinger [EMAIL PROTECTED] wrote: On 3/6/06, Julius Hacker [EMAIL PROTECTED] wrote: Curt Zirzow wrote: I assume your loop is something like: while(condition) { $auction_parts['id'] = 'some value'; $auction_parts['name'] = 'some value'; ... $insert-execute(); } Yes, thats it. My first guess would be, if not aleady done, initialize $auction_parts before you do your bind_param() with something like: $auction_parts = array('id' = null, 'name' = null, ...); $insert-bind_param(issdsis, $auction_house[id], ...); Unfortunately it helps nothing :-( But I think also that it's something because of the declaration and initalization of the variables because it works if I have the bind_param in the loop after I gave the variables their values. But to have the bind_param in the loop isn't the best solution I think. -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php $stmt = $mysqli-prepare(INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)); $stmt-bind_param('sssd', $code, $language, $official, $percent); $code = 'DEU'; $language = 'Bavarian'; $official = F; $percent = 11.2; /* execute prepared statement */ $stmt-execute(); http://us2.php.net/manual/en/function.mysqli-stmt-bind-param.php Table 1. Type specification chars Character Description i corresponding variable has type integer d corresponding variable has type double s corresponding variable has type string b corresponding variable is a blob and will be send in packets 'sssd' defines the datatypes of the 4 arguments you're passing in. I know the example ;-) I checked the statement now without the loop, but defined the variables also after the bind_param. Very interesting is that it works if I write $auction_parts[...] = ...; but that it doesn't if I write $auction_parts = array(... = ..., ...); -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
On Mon, Mar 06, 2006 at 10:03:10PM +0100, Julius Hacker wrote: Curt Zirzow wrote: I assume your loop is something like: while(condition) { $auction_parts['id'] = 'some value'; $auction_parts['name'] = 'some value'; ... $insert-execute(); } Yes, thats it. My first guess would be, if not aleady done, initialize $auction_parts before you do your bind_param() with something like: $auction_parts = array('id' = null, 'name' = null, ...); $insert-bind_param(issdsis, $auction_house[id], ...); Unfortunately it helps nothing :-( Ok, i didn't really think it would but might have shown a obvious bug with mysqli. According to your original post it was odd that the update prepared statment didn't complain about a NULL value, but the insert did, and it does seem to be related to bind_param and prepare. What are your versions of: php? mysql_client php is built with? mysql server you are connecting to? But I think also that it's something because of the declaration and initalization of the variables because it works if I have the bind_param in the loop after I gave the variables their values. But to have the bind_param in the loop isn't the best solution I think. agreed. Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
Curt Zirzow wrote: I assume your loop is something like: while(condition) { $auction_parts['id'] = 'some value'; $auction_parts['name'] = 'some value'; ... $insert-execute(); } Yes, thats it. My first guess would be, if not aleady done, initialize $auction_parts before you do your bind_param() with something like: $auction_parts = array('id' = null, 'name' = null, ...); $insert-bind_param(issdsis, $auction_house[id], ...); Unfortunately it helps nothing :-( But I think also that it's something because of the declaration and initalization of the variables because it works if I have the bind_param in the loop after I gave the variables their values. But to have the bind_param in the loop isn't the best solution I think. -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
MySQL returns Column 'auction_house' cannot be null. Here're some parts of my code: --- code --- $update = $this-sql-stmt_init(); $update-prepare(UPDATE auctions SET name=?, auction_house=?, link=?, prize=?, runtime=?, bids=?, picture=? WHERE link=?); $update-bind_param(sisdsiss, $auction_parts[name], $auction_house[id], $auction_parts[link], $auction_parts[prize], $auction_parts[runtime], $auction_parts[bids], $auction_parts[picture], $auction_parts[link]); $insert = $this-sql-stmt_init(); $insert-prepare(INSERT INTO auctions (auction_house, name, link, prize, runtime, bids, picture) VALUES (?, ?, ?, ?, ?, ?, ?)); $insert-bind_param(issdsis, $auction_house[id], $auction_parts[name], $auction_parts[link], $auction_parts[prize], $auction_parts[runtime], $auction_parts[bids], $auction_parts[picture]); --- /code --- after this, there's the loop, in which I do either $update-execute(); or $insert-execute(); - the $update-execute(); runs without problems but the $insert-execute runs into the described problem. So at some point the $auction_parts['id'] is empty. As you go into the loop, print out the $auction_house[id], then work backwards... -- 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] Prepared statements
chris smith wrote: So at some point the $auction_parts['id'] is empty. As you go into the loop, print out the $auction_house[id], then work backwards... I output already some variables in the loop and all are set with correct values. As I said, if I do the bind_param inside the loop it works without problems. So there's a difference in doing it before the loop and inside the loop causing this problem. -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
On Sun, Mar 05, 2006 at 04:03:17AM +0100, Julius Hacker wrote: On 3/4/06, Julius Hacker [EMAIL PROTECTED] wrote: Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and mysql_stmt_bind_param. In the foreach-loop I give the variables, which I bound with bind_param, their values and want to execute the statement. But now MySQL returns always an error. It seems that the values I gave the variables in the loop aren't used because I used bind_param before that. In the example for mysql_bind_param they do it like me. Is the example also wrong or do I have to consider something special? ... MySQL returns Column 'auction_house' cannot be null. Here're some parts of my code: --- code --- ... $insert = $this-sql-stmt_init(); $insert-prepare(INSERT INTO auctions (auction_house, name, link, prize, runtime, bids, picture) VALUES (?, ?, ?, ?, ?, ?, ?)); $insert-bind_param(issdsis, $auction_house[id], $auction_parts[name], $auction_parts[link], $auction_parts[prize], $auction_parts[runtime], $auction_parts[bids], $auction_parts[picture]); --- /code --- I assume your loop is something like: while(condition) { $auction_parts['id'] = 'some value'; $auction_parts['name'] = 'some value'; ... $insert-execute(); } My first guess would be, if not aleady done, initialize $auction_parts before you do your bind_param() with something like: $auction_parts = array('id' = null, 'name' = null, ...); $insert-bind_param(issdsis, $auction_house[id], ...); Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
On 3/5/06, Curt Zirzow [EMAIL PROTECTED] wrote: On Sun, Mar 05, 2006 at 04:03:17AM +0100, Julius Hacker wrote: On 3/4/06, Julius Hacker [EMAIL PROTECTED] wrote: Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and mysql_stmt_bind_param. In the foreach-loop I give the variables, which I bound with bind_param, their values and want to execute the statement. But now MySQL returns always an error. It seems that the values I gave the variables in the loop aren't used because I used bind_param before that. In the example for mysql_bind_param they do it like me. Is the example also wrong or do I have to consider something special? ... MySQL returns Column 'auction_house' cannot be null. Here're some parts of my code: --- code --- ... $insert = $this-sql-stmt_init(); $insert-prepare(INSERT INTO auctions (auction_house, name, link, prize, runtime, bids, picture) VALUES (?, ?, ?, ?, ?, ?, ?)); $insert-bind_param(issdsis, $auction_house[id], $auction_parts[name], $auction_parts[link], $auction_parts[prize], $auction_parts[runtime], $auction_parts[bids], $auction_parts[picture]); --- /code --- I assume your loop is something like: while(condition) { $auction_parts['id'] = 'some value'; $auction_parts['name'] = 'some value'; ... $insert-execute(); } My first guess would be, if not aleady done, initialize $auction_parts before you do your bind_param() with something like: $auction_parts = array('id' = null, 'name' = null, ...); $insert-bind_param(issdsis, $auction_house[id], ...); Curt. -- cat .signature: No such file or directory -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php might want to read up on bind_param. I'ts been awhile since I did this in Perl. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
One other thing: If I do the bind_param within the loop, it just works. The curious is that I have to prepared statements for this loop (one for inserting data and one for updating data) and the one for updating data works and that for inserting don't. Both statements are 100% valid. Julius Hacker wrote: Hi, so I need help again: I want to use prepared statements to insert lots of data in my MySQL-database. For that I use foreach because I have an array containing all necessary information. Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and mysql_stmt_bind_param. In the foreach-loop I give the variables, which I bound with bind_param, their values and want to execute the statement. But now MySQL returns always an error. It seems that the values I gave the variables in the loop aren't used because I used bind_param before that. In the example for mysql_bind_param they do it like me. Is the example also wrong or do I have to consider something special? -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
On 3/4/06, Julius Hacker [EMAIL PROTECTED] wrote: One other thing: If I do the bind_param within the loop, it just works. The curious is that I have to prepared statements for this loop (one for inserting data and one for updating data) and the one for updating data works and that for inserting don't. Both statements are 100% valid. Julius Hacker wrote: Hi, so I need help again: I want to use prepared statements to insert lots of data in my MySQL-database. For that I use foreach because I have an array containing all necessary information. Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and mysql_stmt_bind_param. In the foreach-loop I give the variables, which I bound with bind_param, their values and want to execute the statement. But now MySQL returns always an error. It seems that the values I gave the variables in the loop aren't used because I used bind_param before that. In the example for mysql_bind_param they do it like me. Is the example also wrong or do I have to consider something special? -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Can you dump the error string reported back from the mysql database connection? Could provide some insight as to why your INSERT fails, and the UPDATE works. -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
Anthony Ettinger wrote: On 3/4/06, Julius Hacker [EMAIL PROTECTED] wrote: One other thing: If I do the bind_param within the loop, it just works. The curious is that I have to prepared statements for this loop (one for inserting data and one for updating data) and the one for updating data works and that for inserting don't. Both statements are 100% valid. Julius Hacker wrote: Hi, so I need help again: I want to use prepared statements to insert lots of data in my MySQL-database. For that I use foreach because I have an array containing all necessary information. Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and mysql_stmt_bind_param. In the foreach-loop I give the variables, which I bound with bind_param, their values and want to execute the statement. But now MySQL returns always an error. It seems that the values I gave the variables in the loop aren't used because I used bind_param before that. In the example for mysql_bind_param they do it like me. Is the example also wrong or do I have to consider something special? -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Can you dump the error string reported back from the mysql database connection? Could provide some insight as to why your INSERT fails, and the UPDATE works. MySQL returns Column 'auction_house' cannot be null. Here're some parts of my code: --- code --- $update = $this-sql-stmt_init(); $update-prepare(UPDATE auctions SET name=?, auction_house=?, link=?, prize=?, runtime=?, bids=?, picture=? WHERE link=?); $update-bind_param(sisdsiss, $auction_parts[name], $auction_house[id], $auction_parts[link], $auction_parts[prize], $auction_parts[runtime], $auction_parts[bids], $auction_parts[picture], $auction_parts[link]); $insert = $this-sql-stmt_init(); $insert-prepare(INSERT INTO auctions (auction_house, name, link, prize, runtime, bids, picture) VALUES (?, ?, ?, ?, ?, ?, ?)); $insert-bind_param(issdsis, $auction_house[id], $auction_parts[name], $auction_parts[link], $auction_parts[prize], $auction_parts[runtime], $auction_parts[bids], $auction_parts[picture]); --- /code --- after this, there's the loop, in which I do either $update-execute(); or $insert-execute(); - the $update-execute(); runs without problems but the $insert-execute runs into the described problem. -- Regards Julius Hacker -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Prepared statements
are you executing the statement in your loop too? On 3/3/06, Julius Hacker [EMAIL PROTECTED] wrote: Hi, so I need help again: I want to use prepared statements to insert lots of data in my MySQL-database. For that I use foreach because I have an array containing all necessary information. Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and mysql_stmt_bind_param. In the foreach-loop I give the variables, which I bound with bind_param, their values and want to execute the statement. But now MySQL returns always an error. It seems that the values I gave the variables in the loop aren't used because I used bind_param before that. In the example for mysql_bind_param they do it like me. Is the example also wrong or do I have to consider something special? -- Regards Julius Hacker http://www.julius-hacker.de [EMAIL PROTECTED] OpenPGP-Key-ID: 0x4B4A486E -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Anthony Ettinger Signature: http://chovy.dyndns.org/hcard.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] setcookie statements are giving me error
* Thus wrote Ryan Schefke ([EMAIL PROTECTED]): cannot modify header errors, which tells me there's nothing wrong with my main script. Am I doing something wrong with cookies here? Warning: Cannot modify header information - headers already sent by. You're missing the most important part of the message, like at exactly what line the output started. setcookie (acctActive_ck, $daysRemaining); //set cookie for active account, will terminate when browser window closes if (setcookie(acctActive_ck)) { echo active cookie set; } else { echo active cookie not set;} No other cookie can be set after this line. Headers are sent once you echo something. 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] setcookie statements are giving me error
Curt, Thanks. That was the issue. Am I allowed to redirect directly below the setcookie functions using header ('Location Thanks, Ryan == -Original Message- From: Curt Zirzow [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 14, 2004 3:29 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] setcookie statements are giving me error * Thus wrote Ryan Schefke ([EMAIL PROTECTED]): cannot modify header errors, which tells me there's nothing wrong with my main script. Am I doing something wrong with cookies here? Warning: Cannot modify header information - headers already sent by. You're missing the most important part of the message, like at exactly what line the output started. setcookie (acctActive_ck, $daysRemaining); //set cookie for active account, will terminate when browser window closes if (setcookie(acctActive_ck)) { echo active cookie set; } else { echo active cookie not set;} No other cookie can be set after this line. Headers are sent once you echo something. 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] echo statements
--- Jay Fitzgerald [EMAIL PROTECTED] wrote: When echoing html code that will include variables from a while or if loop, which method is best? ... Method 1: echo td align=\left\ VALIGN=\top\font class=\dbtables\$employer/font/td; OR Method 2: td align=left valign=topfont class=dbtables?php echo $employer; ?/font/td Method 2 is my choice. If you would, please give reasons why to support your opinion. Readability and performance. Chris = Become a better Web developer with the HTTP Developer's Handbook http://httphandbook.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo statements
Jay Fitzgerald [EMAIL PROTECTED] wrote: When echoing html code that will include variables from a while or if loop, which method is best? Method 1: echo td align=\left\ VALIGN=\top\font class=\dbtables\$employer/font/td; OR Method 2: td align=left valign=topfont class=dbtables?php echo $employer; ?/font/td method 2a: td class=dbtables?php echo $employer?/td If you would, please give reasons why to support your opinion. Thanks - readability - less typing - easier to type no \ or if using ' and together when to use one or the other... etc etc etc - code is easier to read - never use the font tag.. bad.. evil... Curt -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] variable statements
On Thursday 27 June 2002 01:34, Henning Sittler wrote: Question: Variable variables and variable functions work great, but how can you execute arbitrary code statements using php code stored inside variables? eval() -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Speak softly and own a big, mean Doberman. -- Dave Millman */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] variable statements
Perfect. Thank you Jason. Henning Sittler www.inscriber.com -Original Message- From: Jason Wong [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 26, 2002 1:44 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] variable statements On Thursday 27 June 2002 01:34, Henning Sittler wrote: Question: Variable variables and variable functions work great, but how can you execute arbitrary code statements using php code stored inside variables? eval() -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Speak softly and own a big, mean Doberman. -- Dave Millman */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if() statements
On Thu, Jun 06, 2002 at 07:52:28PM +1000, Justin French wrote: It's starting to get a noticeable (although not major) lag. It's probably the multiple MySQL queries, which I'm going to attempt to minimise and optimise, but it also brings me to a question about if(). does the process of PHP digging it's way through multiple nested if() statements slow down PHP, perhaps in comparison to a single line with an include? If() statements definitely slow programs down. BUT, the size of the code inside the if satement isn't the real issue. It's the process of making the true/false decision that takes the work. Of course, the longer the code inside the if statement, the longer it takes run that particular part of the code if that code is executed. I personally like developing with include() files and keeping everything modular, Regarding includes, they add overhead. Includes come in handy where the included file is used in other scripts too. Is there a good way to time scripts too? All I can think of is comparing time() or microtime() from the start and end of the scripts. Yep. That's the simplest thing to do, but I believe there are benchmarking classes/functions out there. --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
RE: [PHP] IF Statements
Hi Jon, Your brackets are just a bit out of sync: Here is a version that parses. You will have to make sure that my change does not affect your intended logic. if ( ($this-checkReferralCB($this-benefitRef, $this-benefitNo,$this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB)) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo)) ) Best Regards, Patrick Lynch. Optip Ltd, Internet Mobile Development http://www.optip.com/ -Original Message- From: Jon Yates [mailto:[EMAIL PROTECTED]] Sent: 15 May 2002 15:04 To: '[EMAIL PROTECTED]' Subject: [PHP] IF Statements People, hope you can help. The below IF statement is getting a PARSE error. Can anyone spot why? Cheers. Jon if (($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB))) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo)) JYvCard.vcf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF Statements
Your brackets don't match up. Use an editor that lets you do bracket-matching. Hit '%' in vi, for example. -Rasmus On Wed, 15 May 2002, Jon Yates wrote: People, hope you can help. The below IF statement is getting a PARSE error. Can anyone spot why? Cheers. Jon if (($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB))) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo)) JYvCard.vcf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF Statements
if (($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB))) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo)) must be: if (($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB)) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo)) ) -- Steven Apostolou [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF Statements
Hello, try this version :) if (($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB)) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo))) Regards, Michal Dvoracek [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] IF Statements
[snip] People, hope you can help. The below IF statement is getting a PARSE error. Can anyone spot why? if (($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB))) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo)) [/snip] It's not complete, where is the {} curly braces? And you're parentheses are out of order by one... if (($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB)) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo))) standard... If((this) (that) (theother) || (something else)){ do this } Jay -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] IF Statements
When in doubt, add in some carriage returns to space everything out to see if your braces match up. if ( ($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB)) ) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo)) You can see from that, that there is a brace missing around the entire statement. So your logic probably isn't working how you thought it would, either. You'll have to put it all back together to actually execute the code, but this will help you on large statements like this to make sure your logic and syntax is correct. ---John Holmes... - Original Message - From: Jon Yates [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, May 15, 2002 10:03 AM Subject: [PHP] IF Statements People, hope you can help. The below IF statement is getting a PARSE error. Can anyone spot why? Cheers. Jon if (($this-checkReferralCB($this-benefitRef, $this-benefitNo, $this-childDOB)) (!$this-checkLocation($this-post, W)) (!empty($this-childDOB))) || ($this-checkPregnancy($this-benefitRef, $this-benefitNo)) JYvCard.vcf -- 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] Case Statements - lil help please
Try the following... // check the error code and generate an appropriate error message switch($e) { case( -1): $message = No such user.; break; case(0): $message = Invalid username and/or password.; break; case(2): $message = Unauthorized access.; break; default: $message = An unspecified error occurred.; break; } - Original Message - From: Patrick Hartnett [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, March 31, 2002 12:03 AM Subject: [PHP] Case Statements - lil help please Are case statements not implemented in PHP4? If so, can someone help me debug this one, I seem to have some syntax incorrect, and am not sure what exactly is wrong with the statement. I get a parse error on the first line, but can't find any documentation on case statements in PHP4, so I am kinda stuck. thanks -Patrick # // check the error code and generate an appropriate error message switch ($e) { case -1: $message = No such user.; break; case 0: $message = Invalid username and/or password.; break; case 2: $message = Unauthorized access.; break; default: $message = An unspecified error occurred.; break; } _ Send and receive Hotmail on your mobile device: http://mobile.msn.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] IF Statements
if ($action=='list') { if (!$clientcode) { old_code } else { new_code } } I put the $clientcode test inside the $action test because I suppose you take different actions on $clientcode depending on $action - if that's not the case, simply switch the two if's. This assumes that $clientcode0. If you also use 0, then test if (!isset($clientcode)) instead. Bogdan Necro wrote: I have a page for listing the contents of a table from my db. Being client.php?action=list As the action variable also allows for adding extra to the table, etc. Once I use ?action=list I want to be able to click on a single record and have it give me the extended info. so client.php?action=listclientcode=(the clients id in the db) My problem is working out how to evaluate this new part. I have normal If statements for the listing, adding, etc. But how can I get it to check if clientcode is present. If clientcode is not present I want it to load the list page as normal. But if the clientcode is present then it is to load something else. How do I structure my IF statement? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] IF Statements
Hi, My problem is working out how to evaluate this new part. I have normal If statements for the listing, adding, etc. But how can I get it to check if clientcode is present. If clientcode is not present I want it to load the list page as normal. But if the clientcode is present then it is to load something else. How do I structure my IF statement? If i understand correctly, you need something like this... $sql = select clientcode from table where clientcode='$var'; $qu = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($qu)=='0') { //does not exist } else { //exists //loop through records here. } hmmz might be wrong... just came back from a few weeks of holidays. Regards, James Mclean Adam Internet Web Design Team » [EMAIL PROTECTED] | www.adam.com.au « » 199 Sturt St. | P: 8231 0303« » Adelaide 5000 | F: 8231 0223« Windows didn't get as bad as it is overnight -- it took over ten years of careful development. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] IF Statements
if (action == list) { if (isset($clientcode)) // or just if ($clientcode) would work... { // extended listing here } else { // normal listing here } } else if -Original Message- From: Necro [mailto:[EMAIL PROTECTED]] Sent: Monday, January 14, 2002 2:09 PM To: [EMAIL PROTECTED] Subject: [PHP] IF Statements I have a page for listing the contents of a table from my db. Being client.php?action=list As the action variable also allows for adding extra to the table, etc. Once I use ?action=list I want to be able to click on a single record and have it give me the extended info. so client.php?action=listclientcode=(the clients id in the db) My problem is working out how to evaluate this new part. I have normal If statements for the listing, adding, etc. But how can I get it to check if clientcode is present. If clientcode is not present I want it to load the list page as normal. But if the clientcode is present then it is to load something else. How do I structure my IF statement? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] while statements output to variables
On Thu, 24 May 2001 10:40, adam wrote: i need to write a while statement to a variable that will later be echoed again on another page after including this file to it. i need to repeat a statement over and over in it and i do not know how. ?php $variable = 'table tr td' . do { 'fontdata to be outputted/font' }while ($something = mysql_fetch_array($query)); .'/td /tr /table'; ? any help? See the manual entry for mysql_fetch_array(), which gives an example of how to do this. You might also find extract() useful. -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA Make it idiot proof and someone will make a better idiot. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] IF statements
What's wrong with doing it like if ($date == 24) { if ($hour == 3) { do something } } ?? -Original Message- From: chris herring [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 23, 2001 12:58 PM To: [EMAIL PROTECTED] Subject: [PHP] IF statements Ok, use your imaginations and visualize what I'm trying to do with this, because I'm not quite sure how to explain it. Anyway, I'm trying to have a script that says when THIS_VAR and THAT_VAR are a certain number it show something. I'm not quite sure how to do that without making yet another var that would screw up things even more. Anyway, this might help some people with what I'm trying to do: if ($date == 24 $hour == 3) { } But that doesn't work... Any help is appreciated -chris Fat people eat.
RE: [PHP] IF statements
Why doesn't work? $date = 24; $hour = 3; if ($date == 24 $hour == 3) { echo 'works'; } If does not print you 'works': the sky will crash to the ground. I think you just got confused elsewhere in your code. Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) [EMAIL PROTECTED] www.phpbeginner.com -Original Message- From: chris herring [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 23, 2001 11:58 AM To: [EMAIL PROTECTED] Subject: [PHP] IF statements Ok, use your imaginations and visualize what I'm trying to do with this, because I'm not quite sure how to explain it. Anyway, I'm trying to have a script that says when THIS_VAR and THAT_VAR are a certain number it show something. I'm not quite sure how to do that without making yet another var that would screw up things even more. Anyway, this might help some people with what I'm trying to do: if ($date == 24 $hour == 3) { } But that doesn't work... Any help is appreciated -chris Fat people eat. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] IF statements
chris herring [EMAIL PROTECTED] wrote: if ($date == 24 $hour == 3) { } But that doesn't work... Any help is appreciated Your logic is correct. If the code within the braces isn't working it's likely there's either an error in the code within the braces or $date and $hour aren't returning the values you expect. Try echoing them before the if statement to verify they contain the values you expect. -- Steve Werby President, Befriend Internet Services LLC http://www.befriend.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]