Re: [PHP] Logic of conditionals and the ( ) operators
On Fri, 2009-12-18 at 10:21 -0800, Allen McCabe wrote: In a nutshell: Will this work? if ($perm == (11 || 12)) Explanation: I am laying the groundwork for a photo viewing system with a private and public mode, and additionally if an admin is logged in, there is an additional level of permission. I came up with a number system to make it easier (and is calcualted by a class) so now, instead of checking against the $mode variable, if the user is logged in, and then what their user level is if they are logged in, I just check against some numbers (the class evaluates all those conditions and assigns the appropriate number a single permission variable, $perm. That equates to if($perm == true) as 11 in this case translates to true (being a positive integer) The code never needs to figure out the || part, as the first part is true. I think what you'd want to do is possibly: if($perm == 11 || $perm == 12) Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Logic of conditionals and the ( ) operators (RESOLVED)
Thank you Ashley, it makes perfect sense. I don't know why I didn't just set up some tests like Shiplu suggested! I've rewritten all my code BACK to the correct way. (I thought it looked cooler, oh well). On Fri, Dec 18, 2009 at 10:47 AM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: On Fri, 2009-12-18 at 10:21 -0800, Allen McCabe wrote: In a nutshell: Will this work? if ($perm == (11 || 12)) Explanation: I am laying the groundwork for a photo viewing system with a private and public mode, and additionally if an admin is logged in, there is an additional level of permission. I came up with a number system to make it easier (and is calcualted by a class) so now, instead of checking against the $mode variable, if the user is logged in, and then what their user level is if they are logged in, I just check against some numbers (the class evaluates all those conditions and assigns the appropriate number a single permission variable, $perm. That equates to if($perm == true) as 11 in this case translates to true (being a positive integer) The code never needs to figure out the || part, as the first part is true. I think what you'd want to do is possibly: if($perm == 11 || $perm == 12) Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Logic of conditionals and the ( ) operators
Hi, Yes, what Ashley said is correct. Also, if you want to avoid writing $perm several times in the if, or if you have a lot of permissions you can do: if (in_array($perm, array(11, 22))) And you can put in that array all the permissions you need to. Regards, Jonathan On Fri, Dec 18, 2009 at 3:47 PM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: On Fri, 2009-12-18 at 10:21 -0800, Allen McCabe wrote: In a nutshell: Will this work? if ($perm == (11 || 12)) Explanation: I am laying the groundwork for a photo viewing system with a private and public mode, and additionally if an admin is logged in, there is an additional level of permission. I came up with a number system to make it easier (and is calcualted by a class) so now, instead of checking against the $mode variable, if the user is logged in, and then what their user level is if they are logged in, I just check against some numbers (the class evaluates all those conditions and assigns the appropriate number a single permission variable, $perm. That equates to if($perm == true) as 11 in this case translates to true (being a positive integer) The code never needs to figure out the || part, as the first part is true. I think what you'd want to do is possibly: if($perm == 11 || $perm == 12) Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic operands problem
Devendra Jadhav wrote: what do you think about this? if( ! (page == 1 page == 2)){ //here } Well a simple (and) does not help. I want to have all results that contain either page = 1 OR page = 3, AND in the same time I want to have the results that contain page=2 OR page= 3 , But the result should never contain page = 1 and page = 2 in the same time. Any further idea? On Mon, Dec 7, 2009 at 4:22 PM, Merlin Morgenstern merli...@fastmail.fm mailto:merli...@fastmail.fm wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Devendra Jadhav देवेंद्र जाधव
Re: [PHP] logic operands problem
On Mon, 2009-12-07 at 11:52 +0100, Merlin Morgenstern wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin I thought this might work: (page = 3) OR (page = 1 XOR 2) But having given it more thought, I'm not so sure. I assume from your example that this is MySQL code and not PHP. Having said that, how can a field of one row have more than one value? Surely `page` is either 1, 2 or 3, not two of them at once. How do you want your results pulled? Assuming you have rows containing all three values, how do you decide which of the pair of results you want? Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] logic operands problem
Ashley Sheridan wrote: On Mon, 2009-12-07 at 11:52 +0100, Merlin Morgenstern wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin I thought this might work: (page = 3) OR (page = 1 XOR 2) But having given it more thought, I'm not so sure. I assume from your example that this is MySQL code and not PHP. Having said that, how can a field of one row have more than one value? Surely `page` is either 1, 2 or 3, not two of them at once. How do you want your results pulled? Assuming you have rows containing all three values, how do you decide which of the pair of results you want? Thanks, Ash http://www.ashleysheridan.co.uk You have described the problem very well. This is exactly where I can not find a solution. the page number translates to the following: 1= first page 2= following pages 3= all pages This are the options a user has while booking a product on my site. Now if ther is a new client that wants to book all pages, I need to query the table to find out if the spot is available. The spot would be full if page 1 has more results then 3 , OR all following pages have more then 3 results. So to find out if all pages option would be available I need to query the db to retrieve all results, that are (page = 3) OR (page = 1 XOR 2) Am I wrong?
Re: [PHP] logic operands problem
On Mon, 2009-12-07 at 12:49 +0100, Merlin Morgenstern wrote: Ashley Sheridan wrote: On Mon, 2009-12-07 at 11:52 +0100, Merlin Morgenstern wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin I thought this might work: (page = 3) OR (page = 1 XOR 2) But having given it more thought, I'm not so sure. I assume from your example that this is MySQL code and not PHP. Having said that, how can a field of one row have more than one value? Surely `page` is either 1, 2 or 3, not two of them at once. How do you want your results pulled? Assuming you have rows containing all three values, how do you decide which of the pair of results you want? Thanks, Ash http://www.ashleysheridan.co.uk You have described the problem very well. This is exactly where I can not find a solution. the page number translates to the following: 1= first page 2= following pages 3= all pages This are the options a user has while booking a product on my site. Now if ther is a new client that wants to book all pages, I need to query the table to find out if the spot is available. The spot would be full if page 1 has more results then 3 , OR all following pages have more then 3 results. So to find out if all pages option would be available I need to query the db to retrieve all results, that are (page = 3) OR (page = 1 XOR 2) Am I wrong? I'm pretty confused by your logic, but I think the only way you can achieve what you want is with multiple queries and counts. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] logic operands problem
Merlin Morgenstern wrote: You have described the problem very well. This is exactly where I can not find a solution. the page number translates to the following: 1= first page 2= following pages 3= all pages This are the options a user has while booking a product on my site. Now if ther is a new client that wants to book all pages, I need to query the table to find out if the spot is available. The spot would be full if page 1 has more results then 3 , OR all following pages have more then 3 results. So to find out if all pages option would be available I need to query the db to retrieve all results, that are (page = 3) OR (page = 1 XOR 2) Am I wrong? Yes I think you are! And XOR may be wrong here. XOR is a binary operator, so think of the number as 0b0011 for 3 0b0010 for 2 and 0b0001 for 1 ... 1 XOR 2 will give a result of 0b0011 - so = 3 What you are trying to do just seems wrong in general. 'if page 1 has more results then 3' requires you count the number of page 1 records and compare with the number of page 3 records. And the same with page 2 results. I don't think you are giving enough detail to know exactly what you are trying to achieve, but what you are describing so far does not make sense 'logically'. If you are trying to book a 'set' of pages but can't if one of that set is already booked, then I don't think you can do this with a single query. You need to check each 'page' individually. If this was room booking, then one would have to check there are no other bookings for a day in the period for that particular room. Or putting it another way, there are no days in the period when all rooms are booked, but in this case you still need to know that a particular room is available for the whole period. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic operands problem
Hey Merlin Merlin Morgenstern wrote on 2009-12-07 11:52: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? I've read the entire thread and can see that this is a MySQL query you want to make (I was about to tell you about the == comparison and the $ in a variable in PHP). What you want is all results containing 1,2 or 3, so make a WHERE page IN(1,2,3) and use PHP logic to figure out if a free slot is available or not. Or rewrite your booking routine (use data and time fields instead, maybe by creating a bunch of free slots and then a booked field with a default of 0, changed to 1 when booked) -- Kind regards Kim Emax - masterminds.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic operands problem
At 11:52 AM +0100 12/7/09, Merlin Morgenstern wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin Merlin: The variable page cannot hold two values at the same time and thus your statement The result should never contain 1 AND 2 in the same time is nonsense. Now if you are working two variables, namely $a and $b and you want an algorithm to solve your problem, it's simple. if ($a + $b 3) { $result = true; } else { $result = false; } 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] logic operands problem
Hi everybody, thank you for all the help and thoughts. I have solved it, but I guess it is not an elegant solution. What I do now, is simply check again for the second case. There are 2 cases. Either first page OR all pages, second case: following pages OR all pages. My booking checking looks now as following: # on which page will the tl be placed? if ($data[page] == 3){ // all pages $where_page = 'AND (page = 1 OR page = 3)'; // unfortunatelly we have to test later on page = 2 OR page = 3. No solution inside one query. We tried also (page=1 XOR page=2) OR page = 3 $where_page_2 = 'AND (page = 2 OR page = 3)'; } else{ // page one or all following pages $where_page = 'AND page = '.$data[page]; } # find out first possible booking period do{ // get all toplistings that are at least with one day inside the desired booking period $stmt= SELECT * FROM $DB.$T54 WHERE cat_id = '$data[cat_id]' AND cat_type = '$data[cat_type]' $where_page AND ( (start_date = '$new_start' AND expires = '$new_start') OR (start_date = '$new_end' AND expires = '$new_end') OR (start_date = '$new_start' AND start_date= '$new_end') ) ; #echo $stmt.$br; $result = execute_stmt($stmt, $link); while ($row = db_get_row($result)){ $booked[start][] = $row-start_date; $booked[end][]= $row-expires; } $possible_bookings = count($booked[start]); // would there be more bookings then possible? if ($possible_bookings = $places){ // not enough space. Try nest day $shift = true; // shift period for one day $reservation = 1; $new_start = date(Ymd,strtotime($new_start. + 1 day)); $new_end = date(Ymd,strtotime($new_end. + 1 day)); } else{ // enough space unset($shift); } unset($booked); } while ($shift); // shift as long as we find free space # if client wants to book all pages, we have to try also the second constellation # we could not find a way to do this in one sql query # find out if booking period has to be shifted even further due to all pages booking if ($page == 3){ do{ // get all toplistings that are at least with one day inside the desired booking period $stmt= SELECT * FROM $DB.$T54 WHERE cat_id = '$data[cat_id]' AND cat_type = '$data[cat_type]' $where_page_2 AND ( (start_date = '$new_start' AND expires = '$new_start') OR (start_date = '$new_end' AND expires = '$new_end') OR (start_date = '$new_start' AND start_date= '$new_end') ) ; //echo $stmt.$br; $result = execute_stmt($stmt, $link); while ($row = db_get_row($result)){ $booked[start][] = $row-start_date; $booked[end][]= $row-expires; } $possible_bookings = count($booked[start]); // would there be more bookings then possible? if ($possible_bookings = $places){ // not enough space. Try nest day $shift = true; // shift period for one day $reservation = 1; $new_start = date(Ymd,strtotime($new_start. + 1 day)); $new_end = date(Ymd,strtotime($new_end. + 1 day)); } else{ // enough space unset($shift); } unset($booked); } while ($shift); // shift as long as we find free space } This is rather a dirty solution. Maybe someone has an idea on how to do it more elegant? I believe there should be one simple line that is different instead of checking it all over again for a second time. Any ideas? Kim Madsen wrote: Hey Merlin Merlin Morgenstern wrote on 2009-12-07 11:52: Hello everybody, I am
Re: [PHP] Logic puzzle. Not a question. Just for fun
If this seems simple to you remember I have no formal training in logic structure or DB design Neither do I - and probably a lot of others here too ;) the value of a status field is given in the sdk text as such... ...This number is determined by adding the following values together: State a = 0 State b = 1 State c = 2 What a bizarre design :( Example: a State a, State i, State k will have a value of 0 + 256 + 4096 = 4352 So does 256 + 4096. State 'a' has no significant value. If it's not included, you get the same as if it is... unless I'm missing something (which is more than likely). -- 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] logic for grabbing what we need from user-input addresses for AVS?
On Sun, 2008-10-19 at 01:10 -0400, Robert Cummings wrote: On Sat, 2008-10-18 at 22:56 -0600, Govinda wrote: Hi all This is not exactly PHP, but an issue that we have to work out in code (whatever we use) - I am working on a shopping cart site which will have orders from any country. To cut down on fraudulent orders, our cc processor (whatever we call them), to enable Address Verification System (AVS), accepts a var/ value which is The numeric portion of the street address. It is Required for AVS. Now to get this from what the user input, I can: - just read the *numeric* characters off the front of the first (of 2) address text inputs, stopping grabbing them once I reach any non- numeric char., or I could - get *any* numeric chars input in that text area and concatenate them all together (if there is more than one continuous run of them), or - get *any* numeric chars input in *either* of the address text areas and concatenate that all together (if there is more than one continuous run of them), or - (what are the other possibilities?) I am asking you guys/gals using AVS: what are they looking for? The docs make this clear that they want: The numeric portion of the street address, but just because I can't think of addresses that don't match a pattern I am thinking of does not mean they don't exist or are not valid. And how should the logic of my algorithm be written if it was just for USA addresses? ... and more importantly - if I am writing it to handle addresses from any country? Thanks for any insight/logic based on experience, ;-) AVS systems I've used don't ask for the street number. They ask for the entire address and they do the matching for me and return a code indicating what portions matched. For one client in particular an AVS fail allows the order to go through, but it is flagged as peculiar and requires someone to manually reject or allow the order to be fulfilled. This was necessary since a lot of AVS failures were encountered for regular clients. If I had to make a choice given your system, I think I would just grab the integer value of the first address line. No concatenation, and no fussing with a second line... $number = (int)$input; Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP It does sound like a bit of a flawed system you are using though, I mean, some addresses have only house names, not numbers, so there would be no number, and what about business addresses in business centres? Unit 3 of Suchandsuch Business Centre, 20-30 Somesuch Road... How would you go about getting the numerical part from that? Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic for grabbing what we need from user-input addresses for AVS?
On Oct 18, 2008, at 11:10 PM, Robert Cummings wrote: On Sat, 2008-10-18 at 22:56 -0600, Govinda wrote: To cut down on fraudulent orders, our cc processor (whatever we call them), to enable Address Verification System (AVS), ... The docs make this clear that they want: The numeric portion of the street address, ... And how should the logic of my algorithm be written if it was just for USA addresses? ... and more importantly - if I am writing it to handle addresses from any country? AVS systems I've used don't ask for the street number. They ask for the entire address and they do the matching for me and return a code indicating what portions matched. For one client in particular an AVS fail allows the order to go through, but it is flagged as peculiar and requires someone to manually reject or allow the order to be fulfilled. This was necessary since a lot of AVS failures were encountered for regular clients. If I had to make a choice given your system, I think I would just grab the integer value of the first address line. No concatenation, and no fussing with a second line... $number = (int)$input; Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP Yes, here also they want the entire billing data for different checks to be run on the card validity (like postal code check, card security code check, etc.), but for just this AVS (address) check in particular, which I am asking about, they explicitly state which part of that billing data they use: The numeric portion of the street address Thanks all for your replies! -Govinda -- (I have so much work that I have never bothered about my resume, personal business site, sig file.. nothing. Nor do I have any fun quote generator lined up. But since it is Sunday, and sig files seem to be tolerated well, here's one quote off the top of my head: Now we measure power in terms of nourishing ability. -Maharishi Mahesh Yogi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic for grabbing what we need from user-input addresses for AVS?
On Sun, 2008-10-19 at 10:03 +0100, Ashley Sheridan wrote: On Sun, 2008-10-19 at 01:10 -0400, Robert Cummings wrote: On Sat, 2008-10-18 at 22:56 -0600, Govinda wrote: Hi all This is not exactly PHP, but an issue that we have to work out in code (whatever we use) - I am working on a shopping cart site which will have orders from any country. To cut down on fraudulent orders, our cc processor (whatever we call them), to enable Address Verification System (AVS), accepts a var/ value which is The numeric portion of the street address. It is Required for AVS. Now to get this from what the user input, I can: - just read the *numeric* characters off the front of the first (of 2) address text inputs, stopping grabbing them once I reach any non- numeric char., or I could - get *any* numeric chars input in that text area and concatenate them all together (if there is more than one continuous run of them), or - get *any* numeric chars input in *either* of the address text areas and concatenate that all together (if there is more than one continuous run of them), or - (what are the other possibilities?) I am asking you guys/gals using AVS: what are they looking for? The docs make this clear that they want: The numeric portion of the street address, but just because I can't think of addresses that don't match a pattern I am thinking of does not mean they don't exist or are not valid. And how should the logic of my algorithm be written if it was just for USA addresses? ... and more importantly - if I am writing it to handle addresses from any country? Thanks for any insight/logic based on experience, ;-) AVS systems I've used don't ask for the street number. They ask for the entire address and they do the matching for me and return a code indicating what portions matched. For one client in particular an AVS fail allows the order to go through, but it is flagged as peculiar and requires someone to manually reject or allow the order to be fulfilled. This was necessary since a lot of AVS failures were encountered for regular clients. If I had to make a choice given your system, I think I would just grab the integer value of the first address line. No concatenation, and no fussing with a second line... $number = (int)$input; It does sound like a bit of a flawed system you are using though, I mean, some addresses have only house names, not numbers, so there would be no number, and what about business addresses in business centres? Unit 3 of Suchandsuch Business Centre, 20-30 Somesuch Road... How would you go about getting the numerical part from that? Is this targetted at me? Doesn't seem applicable to my own case since I pass the entire address to the payment gateway. 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] logic for grabbing what we need from user-input addresses for AVS?
On Sun, 2008-10-19 at 11:26 -0400, Robert Cummings wrote: On Sun, 2008-10-19 at 10:03 +0100, Ashley Sheridan wrote: On Sun, 2008-10-19 at 01:10 -0400, Robert Cummings wrote: On Sat, 2008-10-18 at 22:56 -0600, Govinda wrote: Hi all This is not exactly PHP, but an issue that we have to work out in code (whatever we use) - I am working on a shopping cart site which will have orders from any country. To cut down on fraudulent orders, our cc processor (whatever we call them), to enable Address Verification System (AVS), accepts a var/ value which is The numeric portion of the street address. It is Required for AVS. Now to get this from what the user input, I can: - just read the *numeric* characters off the front of the first (of 2) address text inputs, stopping grabbing them once I reach any non- numeric char., or I could - get *any* numeric chars input in that text area and concatenate them all together (if there is more than one continuous run of them), or - get *any* numeric chars input in *either* of the address text areas and concatenate that all together (if there is more than one continuous run of them), or - (what are the other possibilities?) I am asking you guys/gals using AVS: what are they looking for? The docs make this clear that they want: The numeric portion of the street address, but just because I can't think of addresses that don't match a pattern I am thinking of does not mean they don't exist or are not valid. And how should the logic of my algorithm be written if it was just for USA addresses? ... and more importantly - if I am writing it to handle addresses from any country? Thanks for any insight/logic based on experience, ;-) AVS systems I've used don't ask for the street number. They ask for the entire address and they do the matching for me and return a code indicating what portions matched. For one client in particular an AVS fail allows the order to go through, but it is flagged as peculiar and requires someone to manually reject or allow the order to be fulfilled. This was necessary since a lot of AVS failures were encountered for regular clients. If I had to make a choice given your system, I think I would just grab the integer value of the first address line. No concatenation, and no fussing with a second line... $number = (int)$input; It does sound like a bit of a flawed system you are using though, I mean, some addresses have only house names, not numbers, so there would be no number, and what about business addresses in business centres? Unit 3 of Suchandsuch Business Centre, 20-30 Somesuch Road... How would you go about getting the numerical part from that? Is this targetted at me? Doesn't seem applicable to my own case since I pass the entire address to the payment gateway. Cheers, Rob. Not you Rob, don't be so paranoid ;) I was just saying it for Govinda's benefit, as it seems to be particular to the system he is using, and I just thought I'd point out a couple of the more obvious problems with it. Ash www.ashleysheridan.co.uk
Re: [PHP] logic for grabbing what we need from user-input addresses for AVS?
AVS generally only exists for us and canada and parts of the uk, if I remember correctly. Usually they're just looking for the beginning part of the street address, not the concatenation or anything else like that. No need for apartment numbers, for example if you're just looking at avs. If you're doing a full credit card auth, though, that's a different matter. Waynn On 10/18/08, Govinda [EMAIL PROTECTED] wrote: Hi all This is not exactly PHP, but an issue that we have to work out in code (whatever we use) - I am working on a shopping cart site which will have orders from any country. To cut down on fraudulent orders, our cc processor (whatever we call them), to enable Address Verification System (AVS), accepts a var/ value which is The numeric portion of the street address. It is Required for AVS. Now to get this from what the user input, I can: - just read the *numeric* characters off the front of the first (of 2) address text inputs, stopping grabbing them once I reach any non- numeric char., or I could - get *any* numeric chars input in that text area and concatenate them all together (if there is more than one continuous run of them), or - get *any* numeric chars input in *either* of the address text areas and concatenate that all together (if there is more than one continuous run of them), or - (what are the other possibilities?) I am asking you guys/gals using AVS: what are they looking for? The docs make this clear that they want: The numeric portion of the street address, but just because I can't think of addresses that don't match a pattern I am thinking of does not mean they don't exist or are not valid. And how should the logic of my algorithm be written if it was just for USA addresses? ... and more importantly - if I am writing it to handle addresses from any country? Thanks for any insight/logic based on experience, ;-) -Govinda -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Sent from my mobile device -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic for grabbing what we need from user-input addresses for AVS?
On Sat, 2008-10-18 at 22:56 -0600, Govinda wrote: Hi all This is not exactly PHP, but an issue that we have to work out in code (whatever we use) - I am working on a shopping cart site which will have orders from any country. To cut down on fraudulent orders, our cc processor (whatever we call them), to enable Address Verification System (AVS), accepts a var/ value which is The numeric portion of the street address. It is Required for AVS. Now to get this from what the user input, I can: - just read the *numeric* characters off the front of the first (of 2) address text inputs, stopping grabbing them once I reach any non- numeric char., or I could - get *any* numeric chars input in that text area and concatenate them all together (if there is more than one continuous run of them), or - get *any* numeric chars input in *either* of the address text areas and concatenate that all together (if there is more than one continuous run of them), or - (what are the other possibilities?) I am asking you guys/gals using AVS: what are they looking for? The docs make this clear that they want: The numeric portion of the street address, but just because I can't think of addresses that don't match a pattern I am thinking of does not mean they don't exist or are not valid. And how should the logic of my algorithm be written if it was just for USA addresses? ... and more importantly - if I am writing it to handle addresses from any country? Thanks for any insight/logic based on experience, ;-) AVS systems I've used don't ask for the street number. They ask for the entire address and they do the matching for me and return a code indicating what portions matched. For one client in particular an AVS fail allows the order to go through, but it is flagged as peculiar and requires someone to manually reject or allow the order to be fulfilled. This was necessary since a lot of AVS failures were encountered for regular clients. If I had to make a choice given your system, I think I would just grab the integer value of the first address line. No concatenation, and no fussing with a second line... $number = (int)$input; 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] Logic sought
tedd wrote: If two, or more, users hit the site at the same time then a RACE condition may have one user getting something they didn't ask for or not getting anything at all. The complicated way I figure I could solve this would be to: 1. Generate a random string name for the file -- instead of test.zip, it could be ax12nhg34.zip. Either a random name or one based on the session_id(). I know this will work, but if the user never downloads the file, then the files accumulate on the server. Use cron to run a daily job of 'find /yourtempdir -type f -ctime +1 | xargs rm' Run more often and/or with less ctime if you need the space or the site is very busy. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Logic sought
Write a script that cron runs that checks dates of files and removes 1 month old ones? On Wed, Jul 9, 2008 at 4:45 PM, tedd [EMAIL PROTECTED] wrote: Hi gang: Here's the logic problem. First the site: http://php1.net/b/zip-files/ Now, the site works well enough. The user selects what they want, clicks Submit, the order is assembled in zip file and presented to the user for downloading. However, as it stands now, before the script assembles the test.zip, it deletes (unlinks) the previous test.zip and therein lies the problem. If two, or more, users hit the site at the same time then a RACE condition may have one user getting something they didn't ask for or not getting anything at all. The complicated way I figure I could solve this would be to: 1. Generate a random string name for the file -- instead of test.zip, it could be ax12nhg34.zip. 2. Then when the user selects the download that would trigger a javascript routine that would send the name of the file to be deleted to a slave php script that would unlinks the file. I know this will work, but if the user never downloads the file, then the files accumulate on the server. Does anyone have a better idea? Thanks, 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] Logic sought
On Wed, Jul 9, 2008 at 7:45 PM, tedd [EMAIL PROTECTED] wrote: Hi gang: Here's the logic problem. First the site: http://php1.net/b/zip-files/ Now, the site works well enough. The user selects what they want, clicks Submit, the order is assembled in zip file and presented to the user for downloading. However, as it stands now, before the script assembles the test.zip, it deletes (unlinks) the previous test.zip and therein lies the problem. If two, or more, users hit the site at the same time then a RACE condition may have one user getting something they didn't ask for or not getting anything at all. The complicated way I figure I could solve this would be to: 1. Generate a random string name for the file -- instead of test.zip, it could be ax12nhg34.zip. 2. Then when the user selects the download that would trigger a javascript routine that would send the name of the file to be deleted to a slave php script that would unlinks the file. I know this will work, but if the user never downloads the file, then the files accumulate on the server. Does anyone have a better idea? Thanks, 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 Well this is sort of a question that can only be answered based on some answers such as, what will the request load be on this, how many theoretical files will this generate, just stuff like that. If you aren't worried about cpu load, you can probably use the streams api to make a zip file in memory and spit that out to the user without ever creating a file on demand. If you want this to be fast, then you need to cache zip files or pre-generate them to users and store them in some sort of sane filename based on selected options. This way there isn't randomly generated files being re-created for no reason. The other option is to just generate a random filename and cron-delete them after so long. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Logic sought
generate a unique hash as the name based on the contents of the zip, then if 2 people happen to want exactly the same selection you won't have to build/zip it twice ... just check if the zip happens to exist before trying to build it. have the script do garbage collection on old zip files ... in a script specific 'tmp' dir that stores the created zipfiles ... the GC can kick in on 1% of every requests (and maybe limits itself the ammount of time spent GCing) to elliminate race conditions completely you'll have to use a lock file, which the script needs to exclusively lock before attempting to create the zip ... a failure to get an exclusive lock means having to recheck the zip's existence (chances are some other script just created it). in addition a shared lock should be obtained before trying to read a zip, to avoid reading half written files. Kyle Browning schreef: Write a script that cron runs that checks dates of files and removes 1 month old ones? On Wed, Jul 9, 2008 at 4:45 PM, tedd [EMAIL PROTECTED] wrote: Hi gang: Here's the logic problem. First the site: http://php1.net/b/zip-files/ Now, the site works well enough. The user selects what they want, clicks Submit, the order is assembled in zip file and presented to the user for downloading. However, as it stands now, before the script assembles the test.zip, it deletes (unlinks) the previous test.zip and therein lies the problem. If two, or more, users hit the site at the same time then a RACE condition may have one user getting something they didn't ask for or not getting anything at all. The complicated way I figure I could solve this would be to: 1. Generate a random string name for the file -- instead of test.zip, it could be ax12nhg34.zip. 2. Then when the user selects the download that would trigger a javascript routine that would send the name of the file to be deleted to a slave php script that would unlinks the file. I know this will work, but if the user never downloads the file, then the files accumulate on the server. Does anyone have a better idea? Thanks, 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] Logic sought
On Wed, Jul 9, 2008 at 6:11 PM, Jochem Maas [EMAIL PROTECTED] wrote: generate a unique hash as the name based on the contents of the zip, then if 2 people happen to want exactly the same selection you won't have to build/zip it twice ... just check if the zip happens to exist before trying to build it. have the script do garbage collection on old zip files ... in a script specific 'tmp' dir that stores the created zipfiles ... the GC can kick in on 1% of every requests (and maybe limits itself the ammount of time spent GCing) to elliminate race conditions completely you'll have to use a lock file, which the script needs to exclusively lock before attempting to create the zip ... a failure to get an exclusive lock means having to recheck the zip's existence (chances are some other script just created it). in addition a shared lock should be obtained before trying to read a zip, to avoid reading half written files. if it is a high traffic site, on a *nix host, i recommend the sem* functions from the sysv extension. theyre a lot faster than file locks. -nathan
Re: [PHP] Logic sought
tedd wrote: Hi gang: Here's the logic problem. First the site: http://php1.net/b/zip-files/ Now, the site works well enough. The user selects what they want, clicks Submit, the order is assembled in zip file and presented to the user for downloading. However, as it stands now, before the script assembles the test.zip, it deletes (unlinks) the previous test.zip and therein lies the problem. If two, or more, users hit the site at the same time then a RACE condition may have one user getting something they didn't ask for or not getting anything at all. The complicated way I figure I could solve this would be to: 1. Generate a random string name for the file -- instead of test.zip, it could be ax12nhg34.zip. 2. Then when the user selects the download that would trigger a javascript routine that would send the name of the file to be deleted to a slave php script that would unlinks the file. I know this will work, but if the user never downloads the file, then the files accumulate on the server. Does anyone have a better idea? Thanks, tedd Everybody so far has had excellent descriptions of what to do. I would do almost everything they recommend. Except, if I had the hard drive space to make all the possible permutation and allow them to down load the file that someone else had created, I would do that. Rather then possibly rebuilding an identical file over and over again. So, I guess I need to ask this question. Are their to many files in your download selection too make the number of possible zip archives out of the question to be cached? If that is the case, then I would delete old ones using a cron/task schedule type program. But I would do it much quicker, say every three to seven days. if you are limited on space, you will need to protect yourself against bots that might try, accidentally of course, to to make you run out of HD space. At this point, you might have to build something into your php script to manage the file space consumption. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Logic Help please
Hi, I am doing an online calendar for holiday application. Now I got a table with these fields among many others. `req_id` int(11) NOT NULL auto_increment, `req_date` date NOT NULL, `username` varchar(100) NOT NULL, `start_date` date NOT NULL, `end_date` date NOT NULL, `days_off` int(11) NOT NULL, With start_date is something like [ 1 - 10 - 2007 ] and end_date is like [ 20 - 10 -2007 ]. I am thinking whats the best way to present such data ? and how to show overlapping days between users ? Something like: Jan Feb 1 2 3 4 1 2 3 4 ... + Richard|o o o o o o o o Fred|x x o o o o o o Mohamed|o o o x x o o o With HTML you could use colours to represent days/weeks off making it more apparent, eg. nothing/white for no holiday booked, and red for one booked. And if you're going to go to the day granularity, an IFRAME might be needed with left/right scrolling. -- Richard Heyes +44 (0)800 0213 172 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic with arrays
On Thu, 16 Dec 2004 13:11:02 +1100, Jeffery Fernandez [EMAIL PROTECTED] wrote: I am trying to build a html menu dynamically from data sitting in an array. I have been successful so far until it came to the point of populating the sub-menu of the system. Can someone help me out with the logic or is there a simpler way of doing it? Thanks Hierarchical menus made easy: http://www.sitepoint.com/article/hierarchical-data-database -- Greg Donald Zend Certified Engineer http://gdconsultants.com/ http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic with arrays
Wee Keat wrote: Hey Jeff, How are you mate? Was lazying around and saw your email to the list. :) What exactly do you need help with? Is it the following line? // Stuck here $html_menu .= lia href=\Need to get value\$sub_page/a/li; } $html_menu .= '/ul'; Do you need to get the value of the link and the name of the link? If so, try this: = begin snippet === $html_menu .= 'ul id=subnav'; foreach ($menu_page[$menu_name[1]] as $sub_page = $sub_link) { // Stuck here $html_menu .= lia href=\$sub_link\$sub_page/a/li; } $html_menu .= '/ul'; } = end snippet = What about using recursive functions? I think it's easier as you can create unlimited numbers of sub-menus. It's slow though. Ah Thanks Keat long time no hear/see .. it works now. :-) How are you keeping anyway ? You totally ignore us now at phpMelb :-( Come along to our next meeting on 13th Jan 2005 cheers, Jeffery -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Logic problem
Alex Hogan wrote: Hi All, I am having a logic problem. (insert jokes here) I am trying to create a function that will allow me to pass any number of fields and tables into a blanket query. I am getting an error; Unexpected foreach. I have tried placing the loop in several different places and am getting the same error. What should I be doing differently? Here's my code; function myselect($array1, $array2){ $i = 0; $n = 0; $query = SELECT.foreach($array1 as $flds){ $flds[$i]; }. FROM.foreach($array2 as $tbls){ $tbls[$n]; }.; $result = mssql_query($query); print table width=\100%\ border=\1\ tr; $j = 0; while($row = mssql_fetch_array($result)){ $fields = $row[flds[$j]]; print td.$fields./td/tr; } } You can't concat a construct. Try something like this... $query = SELECT ; $start = true; foreach ( $array1 as $flds ) { if ( $start ) { $query .= $flds[$i]; $start = false; } else { $query .= , . $flds[$i]; } } $query .= FROM ; $start = true; foreach ( $array2 as $tbls ) { if ( $start ) { $query .= $tbls[$n]; $start = false; } else { $query .= , . $tbls[$n]; } } Ugly code, needs tweaking, but you should get the idea. -- *** * _ __ __ __ _ * John Nichel * * | |/ /___ __ \ \/ /__ _ _| |__ ___ __ ___ _ __ * 716.856.9675 * * | ' / -_) _` \ \/\/ / _ \ '_| / /(_-_/ _/ _ \ ' \ * 737 Main St. * * |_|\_\___\__, |\_/\_/\___/_| |_\_\/__(_)__\___/_|_|_|* Suite #150 * * |___/ * Buffalo, NY * * http://www.KegWorks.com[EMAIL PROTECTED] * 14203 - 1321 * *** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Logic problem
[snip] $query = SELECT ; $start = true; foreach ( $array1 as $flds ) { if ( $start ) { $query .= $flds[$i]; $start = false; } else { $query .= , . $flds[$i]; } } $query .= FROM ; $start = true; foreach ( $array2 as $tbls ) { if ( $start ) { $query .= $tbls[$n]; $start = false; } else { $query .= , . $tbls[$n]; } } [/snip] I gotcha.., I do have one question though. I ran your code and it only returns the first letter for that element in the array. For instance fieldone returns as f and tableone returns as t. The output looks like this; SELECT f,f,f FROM t,t. alex ** The contents of this e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. The views stated herein do not necessarily represent the view of the company. If you are not the intended recipient of this e-mail you may not copy, forward, disclose, or otherwise use it or any part of it in any form whatsoever. If you have received this e-mail in error please e-mail the sender. **
RE: [PHP] Logic problem
[snip] I do have one question though. I ran your code and it only returns the first letter for that element in the array. For instance fieldone returns as f and tableone returns as t. The output looks like this; SELECT f,f,f FROM t,t. [/snip] Never mind I found it. It should be; $query = SELECT ; $start = true; $i = 0; foreach ( $array1 as $flds ) { if ( $start ) { $query .= $flds; $start = false; } else { $query .= , . $flds; } } $query .= FROM ; $start = true; $n = 0; foreach ( $array2 as $tbls ) { if ( $start ) { $query .= $tbls; $start = false; } else { $query .= , . $tbls; } } Thanks John, you saved me hours of work. alex ** The contents of this e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. The views stated herein do not necessarily represent the view of the company. If you are not the intended recipient of this e-mail you may not copy, forward, disclose, or otherwise use it or any part of it in any form whatsoever. If you have received this e-mail in error please e-mail the sender. **
Re: [PHP] Logic problem
Apr 20 at 9:55am, Alex Hogan wrote: function myselect($array1, $array2){ $query = SELECT.foreach($array1 as $flds){ $flds[$i]; }. FROM.foreach($array2 as $tbls){ $tbls[$n]; } ... Alex, if you merely wish to place the values of an array into your query, you might also try doing it this way: $query = 'SELECT '. implode(', ', $array1). ' FROM '. implode(', ', $array2). ' ... '; Usually when writing queries, I prefer to use sprintf(): $q = 'SELECT %s FROM %s'; $q = sprintf($q, implode(', ',$array1), implode(', ',$array2)); The more complex the query gets, the easier it is to read using this approach. I'm sure some find that debatable. After all, I'm crazy ;) -- Kelly Hallman -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Logic problem
On 20 April 2004 16:44, Alex Hogan wrote: foreach ( $array1 as $flds ) { if ( $start ) { $query .= $flds; $start = false; } else { $query .= , . $flds; } } $query .= implode(, , $array1); Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Logic problem
Alex Hogan wrote: snip I gotcha.., I do have one question though. I ran your code and it only returns the first letter for that element in the array. For instance fieldone returns as f and tableone returns as t. The output looks like this; SELECT f,f,f FROM t,t. alex What's in your array? -- *** * _ __ __ __ _ * John Nichel * * | |/ /___ __ \ \/ /__ _ _| |__ ___ __ ___ _ __ * 716.856.9675 * * | ' / -_) _` \ \/\/ / _ \ '_| / /(_-_/ _/ _ \ ' \ * 737 Main St. * * |_|\_\___\__, |\_/\_/\___/_| |_\_\/__(_)__\___/_|_|_|* Suite #150 * * |___/ * Buffalo, NY * * http://www.KegWorks.com[EMAIL PROTECTED] * 14203 - 1321 * *** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Logic problem
What's in your array? $array1[0] = 'firstname'; $array1[1] = 'lastname'; $array1[2] = 'tkt_title'; I got that fixed. Thanks. alex hogan ** The contents of this e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. The views stated herein do not necessarily represent the view of the company. If you are not the intended recipient of this e-mail you may not copy, forward, disclose, or otherwise use it or any part of it in any form whatsoever. If you have received this e-mail in error please e-mail the sender. **
Re: [PHP] Logic headache, please help.
How about building an array of all the levels: $a = array(); for ($i = 1; $i = $maxlevels; $i++) $a[] = $i; then for each level you can create a new array that is the difference between the original array and an array that contains the current level: for ($i = 1; $i = $maxlevels; $i++) $a1 = ; echo 'option value=' . implode ('|', array_diff ($a, array($i))) . 'Level ' . $i; I'm not 100% that this will work right off the bat, but it should at least put you on the right track... if not out of your misery :-) Hope this helps. Marco -- php|architect - The magazine for PHP Professionals The first monthly worldwide magazine dedicated to PHP programmers Check us out on the web at http://www.phparch.com On Mon, 2002-11-11 at 09:48, Tony Crockford wrote: Hi all, brief explanation: I'm building a select list, to exclude certain directories from a search (with Ht://dig). The structure is like this: select name=exclude option value=All levels/option option value=/lv2/|/lv3/|/lv4/Level 1/option option value=/lv1/|/lv3/|/lv4/Level 2/option option value=/lv1/|/lv2/|/lv4/Level 3/option option value=/lv1/|/lv2/|/lv3/Level 4/option /select for four levels, where the option value should be all lv's except the current option level. I have a variable $maxlevels to count up to however many levels are required and I want to make this select list work based on the value of $maxlevels. How would you approach the building of the list? I was going to use a while loop or two, but I'm stuck at the point of creating the value string which should contain all the levels from 1 to $maxlevels except the current level. which would seem to require some sort of conditional if $thislevel string is type of approach, but I can't get my head round it. Anyone put me out of my misery? Thanks Tony -- 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] Logic headache, please help.
-Original Message- From: Marco Tabini [mailto:marcot;tabini.ca] Sent: 11 November 2002 14:46 To: Tony Crockford Cc: Php-GeneralLists. Php. Net Subject: Re: [PHP] Logic headache, please help. How about building an array of all the levels: $a = array(); for ($i = 1; $i = $maxlevels; $i++) $a[] = $i; then for each level you can create a new array that is the difference between the original array and an array that contains the current level: for ($i = 1; $i = $maxlevels; $i++) $a1 = ; echo 'option value=' . implode ('|', array_diff ($a, array($i))) . 'Level ' . $i; I'm not 100% that this will work right off the bat, but it should at least put you on the right track... if not out of your misery :-) Hope this helps. It looks like it might, but I note this warning in the manual re:array_diff Warning This was broken in PHP 4.0.4! http://www.php.net/manual/en/function.array-diff.php is it fixed in 4.06 do you know? (host uses 4.06, I have 4.2.2) TIA Tony -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Logic headache, please help.
My guess is it works... but only one way to find out--try it! :-) Marco -- php|architect - The magazine for PHP Professionals The first monthly worldwide magazine dedicated to PHP programmers Check us out on the web at http://www.phparch.com On Mon, 2002-11-11 at 10:19, Tony Crockford wrote: -Original Message- From: Marco Tabini [mailto:marcot;tabini.ca] Sent: 11 November 2002 14:46 To: Tony Crockford Cc: Php-GeneralLists. Php. Net Subject: Re: [PHP] Logic headache, please help. How about building an array of all the levels: $a = array(); for ($i = 1; $i = $maxlevels; $i++) $a[] = $i; then for each level you can create a new array that is the difference between the original array and an array that contains the current level: for ($i = 1; $i = $maxlevels; $i++) $a1 = ; echo 'option value=' . implode ('|', array_diff ($a, array($i))) . 'Level ' . $i; I'm not 100% that this will work right off the bat, but it should at least put you on the right track... if not out of your misery :-) Hope this helps. It looks like it might, but I note this warning in the manual re:array_diff Warning This was broken in PHP 4.0.4! http://www.php.net/manual/en/function.array-diff.php is it fixed in 4.06 do you know? (host uses 4.06, I have 4.2.2) TIA Tony -- 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
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
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
Re: [PHP] Logic
You need parentheses around the entire antecedent: if (($type !=add) || ($type !=edit) || ($type !=delete)) { //etc ^--- Note these parentheses---^ Hope that helps. At 05:28 PM 12/4/2001, Dan McCullough wrote: Question. I am trying to check to see if a certain piece of code should be run. Here is an example. if ($type != add) || ($type != edit) || ($type != delete) {//if this or this or this then then run this code } else { then run this } Is this correct, for some reason this isn't working. Sliante, Richard S. Crawford http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford MSN: [EMAIL PROTECTED] It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- 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] Logic
that didnt work,i started off with if ($type != add) { that works } else { this works } I have done this before I'm just having a brain cramp. if (($type != add) || ($type != edit) || ($type != delete)) { print $subcat_output; } else { print TRTD BGCOLOR=\#F7F7F7\ WIDTH=\20%\/TDTD BGCOLOR=\#F7F7F7\ WIDTH=\80%\FONT FACE=\Verdana, Arial, Tahoma\ SIZE=\2\ COLOR=\#00\a href=.$PHP_SELF.?area=subcategoryBack to List of Subcategories/FONT/TD/tr; } --- Richard S. Crawford [EMAIL PROTECTED] wrote: You need parentheses around the entire antecedent: if (($type !=add) || ($type !=edit) || ($type !=delete)) { //etc ^--- Note these parentheses---^ Hope that helps. At 05:28 PM 12/4/2001, Dan McCullough wrote: Question. I am trying to check to see if a certain piece of code should be run. Here is an example. if ($type != add) || ($type != edit) || ($type != delete) {//if this or this or this then then run this code } else { then run this } Is this correct, for some reason this isn't working. Sliante, Richard S. Crawford http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford MSN: [EMAIL PROTECTED] It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- 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] = dan mccullough Theres no such thing as a problem unless the servers are on fire! __ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Logic
now change || to and see if that does the job -Original Message- From: Dan McCullough [mailto:[EMAIL PROTECTED]] Sent: Wednesday, December 05, 2001 12:57 PM To: PHP General List Cc: Richard S. Crawford Subject: Re: [PHP] Logic that didnt work,i started off with if ($type != add) { that works } else { this works } I have done this before I'm just having a brain cramp. if (($type != add) || ($type != edit) || ($type != delete)) { print $subcat_output; } else { print TRTD BGCOLOR=\#F7F7F7\ WIDTH=\20%\/TDTD BGCOLOR=\#F7F7F7\ WIDTH=\80%\FONT FACE=\Verdana, Arial, Tahoma\ SIZE=\2\ COLOR=\#00\a href=.$PHP_SELF.?area=subcategoryBack to List of Subcategories/FONT/TD/tr; } --- Richard S. Crawford [EMAIL PROTECTED] wrote: You need parentheses around the entire antecedent: if (($type !=add) || ($type !=edit) || ($type !=delete)) { //etc ^--- Note these parentheses---^ Hope that helps. At 05:28 PM 12/4/2001, Dan McCullough wrote: Question. I am trying to check to see if a certain piece of code should be run. Here is an example. if ($type != add) || ($type != edit) || ($type != delete) {//if this or this or this then then run this code } else { then run this } Is this correct, for some reason this isn't working. Sliante, Richard S. Crawford http://www.mossroot.com AIM: Buffalo2K ICQ: 11646404 Y!: rscrawford MSN: [EMAIL PROTECTED] It is only with the heart that we see rightly; what is essential is invisible to the eye. --Antoine de Saint Exupéry Push the button, Max! -- 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] = dan mccullough Theres no such thing as a problem unless the servers are on fire! __ Do You Yahoo!? Buy the perfect holiday gifts at Yahoo! Shopping. http://shopping.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Logic
Dan McCullough [EMAIL PROTECTED] wrote: Question. I am trying to check to see if a certain piece of code should be run. Here is an example. if ($type != add) || ($type != edit) || ($type != delete) {//if this or this or this then then run this code As pointed out, your paranthesis will give an error. Also, || means OR and I suspect you mean which means AND. Why? Go through the logic and you'll see that no matter what $type is, one of the 3 inequalities will be true and since you use an || the entire if statement will evaluate to true. Not what you want. It might be easier to edit and follow your code if you rewrite as: if ( ! in_array( $type, array( 'add', 'edit', 'delete' ) ) ) { } -- 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]
Re: [PHP]logic question
try: http://php.resourceindex.com/Complete_Scripts/Link_Management/ you should be able to find some examples here. __ Do You Yahoo!? Make international calls for as low as $.04/minute with Yahoo! Messenger http://phonecard.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]