[PHP] Logic of conditionals and the ( ) operators

2009-12-18 Thread Allen McCabe
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.


Re: [PHP] Logic of conditionals and the ( ) operators

2009-12-18 Thread Ashley Sheridan
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)

2009-12-18 Thread Allen McCabe
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

2009-12-18 Thread Jonathan Tapicer
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

2009-12-07 Thread Merlin Morgenstern



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

2009-12-07 Thread Ashley Sheridan
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

2009-12-07 Thread Merlin Morgenstern



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

2009-12-07 Thread Ashley Sheridan
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

2009-12-07 Thread Lester Caine

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

2009-12-07 Thread Kim Madsen

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

2009-12-07 Thread tedd

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

2009-12-07 Thread Merlin Morgenstern
 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)




[PHP] Logic puzzle. Not a question. Just for fun

2009-01-06 Thread Frank Stanovcak
This is verbatim from the manufacturer except I replaced the code info with 
vanilia filler to keep from getting in trouble with them.

See how long it takes you to write the shortest SQL code that returns all 
State a and State f records.

If this seems simple to you remember I have no formal training in logic 
structure or DB design, and yes I know the answer.  E-mail me if you want 
it.

Frank.

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
State d = 3
State e = 4
State f = 5
State g = 6
State h = 255
+
State i:
No = 0
Yes = 256
+
State j:
No = 0
Yes = 1024
+
State k:
No = 0
Yes = 4096
+
State l:
No = 0
Yes = 8192
+
State m:
No = 0
Yes = 16384

Example: a State a, State i, State k will have a value of
0 + 256 + 4096 = 4352



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Logic puzzle. Not a question. Just for fun

2009-01-06 Thread Chris
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?

2008-10-19 Thread Ashley Sheridan
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?

2008-10-19 Thread Govinda


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?

2008-10-19 Thread Robert Cummings
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?

2008-10-19 Thread Ashley Sheridan
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


[PHP] logic for grabbing what we need from user-input addresses for AVS?

2008-10-18 Thread Govinda

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



Re: [PHP] logic for grabbing what we need from user-input addresses for AVS?

2008-10-18 Thread Waynn Lue
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?

2008-10-18 Thread Robert Cummings
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

2008-07-10 Thread Per Jessen
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



[PHP] Logic sought

2008-07-09 Thread tedd

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

2008-07-09 Thread Kyle Browning
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

2008-07-09 Thread Eric Butera
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

2008-07-09 Thread Jochem Maas

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

2008-07-09 Thread Nathan Nobbe
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

2008-07-09 Thread Jim Lucas

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



[PHP] Logic Help please

2007-11-22 Thread Mohamed Jama
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 ?


Thanks very much in advance



-Original Message-
From: Simeon F. Willbanks [mailto:[EMAIL PROTECTED] 
Sent: 22 November 2007 15:23
To: php-general@lists.php.net
Subject: Re: [PHP] Code Critique Please :)

No I did not, thanks!  For those that need more information, here is a  
good tutorial:

http://en.wikibooks.org/wiki/XML_-_Managing_Data_Exchange/Converting_MySQL_to_XML

Simeon

On Nov 22, 2007, at 10:05 AM, [EMAIL PROTECTED]  
wrote:

 You know that mysql has an output option for producing XML ?


 /Per Jessen, Zürich

-- 
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 Help please

2007-11-22 Thread Richard Heyes

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

2004-12-15 Thread Greg Donald
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



[PHP] logic with arrays

2004-12-15 Thread Jeffery Fernandez
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

?php
/**
  * This function builds the applications menu system from and array of 
key/pair values
  * @param null
  * @return string $menu contains value of menu structure in html
  */  
 function BuildMenu()
 {

 $base_path = 'http://kangaroo.hotshot/dev/fpaa/DEVELOPMENT/TEST';
 $menu_structure =
   array
   (  
 array('Home' = '/'),
 array(
'News' = '/news', 'sub' =
array(
'Archive' = '?news=archive'
 )
  ),
 array('Events' = '/events'),
 array('About' = '/about'),
 array('Membership' = '/membership'),
 array('Committees' = '/committee'),
 array('Safety' = '/safety'),
 array(
 'Providers' = '/providers', 'sub' =
 array(
'Sprinklers' = '?providers=sprinklers',
'Detection' = '?providers=detection',
'Certification' = '?providers=certification',
'Monitoring' = '?providers=monitoring',
'Hose Reels' = '?providers=hosereels',
'Passive' = '?providers=passive',
'Portable' = '?providers=portable',
'Hazard' = '?providers=hazard',
'Maintenance' = '?providers=maintenance',
'Consultants' = '?providers=consultants',
'Emergency Training' = '?providers=training',

  )
  ),
 array('Licencing' = '/licencing'),
 array(
 'Training' = '/training', 'sub' =
 array(
   'Tafe Courses' = '?courses=tafe',
   'Trade Courses' = '?courses=trade',
   'New Courses' = '?courses=new',
   'RTO Status' = '?courses=rtostatus',
   'Portable' = '?courses=portable',
   'Assessor' = '?courses=assessor',
   'Training Builetin' = '?courses=builetin',
   'Contact' = '?courses=contact'   
 )
  ),
 array('Publication' = '/publication'),
 array('Contact' = '/contact'),
   );

   $html_menu = 'ul id=topnav';
   
   foreach ($menu_structure as $menu_page)
   {
 $menu_name = array_keys($menu_page);
 $menu_value = array_values($menu_page);

 //$html_menu .= li$menu_name[0] - $menu_value[0]/li;
 
 $html_menu .= lia 
href=\$base_path$menu_value[0]\$menu_name[0]/a/li;
 
 $sub_menu = sizeof($menu_name);
 
 if ($sub_menu  1)
 {
   $html_menu .= 'ul id=subnav';
   foreach ($menu_page[$menu_name[1]] as $sub_page)
   {
 // Stuck here
 $html_menu .= lia href=\Need to get 
value\$sub_page/a/li;
   }
   $html_menu .= '/ul';
 }
 
   }
   
   $html_menu .= '/ul';
   
   echo $html_menu;
   
   
   // Example Structure of html menu
   /*
 ul id=topnav
 lia href=#Home/a/li
 lia href=#News/a/li
 lia href=#Events/a/li
 lia href=#About/a/li
 lia href=#Membership/a/li
 lia href=#Committees/a/li
 lia href=#Safety/a/li
 li class=centera href=# class=hereProviders/a
   ul id=subnav
 lia href=#Sprinklers/a/li
 lia href=#Detection/a/li
 lia href=# class=hereCertification/a/li
 lia href=#Monitoring/a/li
 lia href=#Hose Reels/a/li
 lia href=#Passive/a/li
 lia href=#Portable/a/li
 lia href=#Hazard/a/li
 lia href=#Maintenance/a/li
 lia href=#Consultants/a/li
 lia href=#Emergency Training/a/li
   /ul
 /li
 lia href=#Licencing/a/li
 lia href=#Training/a/li
 lia href=#Publication/a/li
 lia href=#Contact/a/li
   /ul
   */
   return $menu_structure;
 }

 print_r(BuildMenu());
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] logic with arrays

2004-12-15 Thread Jeffery Fernandez
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


[PHP] PHP logic - Whats going on here?

2004-08-11 Thread Kim Steinhaug
Ive stumbled onto a rather strange problem, atleast I cant see why this
is happening. Im using phpMailer to send mails, and I have the following
straight forward code :

  $mail = new phpmailer();
  $mail-IsSendmail();
  $mail-From = '[EMAIL PROTECTED]';
  $mail-FromName = 'From Name';
  $mail-AddAddress('[EMAIL PROTECTED]');
  $mail-Subject = $header;
  $mail-Body = $body;

Then to send the mail we use this :
   if(!$mail-Send()) {
  echo $lang_error['mailer_error'] . br\n;
   }

As you see above, Ive dropped the what if all goes well loop, since I
believe that the $mail-Send() is initiaded in the first statement

For some reason the above results in a blank mail, no $body at all,
rest is fine. However, if I include a dummy for if all goes well :

   if(!$mail-Send()) {
  echo $lang_error['mailer_error'] . br\n;
   } else {
  // Why do I need this one???
   }

What I dont understand is why do I need the last else statement? Isnt the
result of $mail-Send() completed if I only check for !$mail-Send()?

Maby it would be better to write like this :
   if(!$mail-Send()) {
  echo $lang_error['mailer_error'] . br\n;
   } else if ($mail-Send()){
  // Why do I need this one???
   }

The above would in my belief send two mails, atleast my logic tells me that.
The strange part is that when looking at examples from
phpmailer.sourceforge.net
they use my initial loop aswell, not the Why do I need this one??? part.
Im beginning to wonder if there are something mystical going on with either
my
code or our servers. ??


Hope someone understand what Im wondering about here, hehe.


-- 

-- 
Kim Steinhaug
-
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
-
www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com
-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Jay Blanchard
[snip]
Then to send the mail we use this :
   if(!$mail-Send()) {
  echo $lang_error['mailer_error'] . br\n;
   }

As you see above, Ive dropped the what if all goes well loop, since I
believe that the $mail-Send() is initiaded in the first statement

For some reason the above results in a blank mail, no $body at all,
rest is fine. However, if I include a dummy for if all goes well :

   if(!$mail-Send()) {
  echo $lang_error['mailer_error'] . br\n;
   } else {
  // Why do I need this one???
   }

What I dont understand is why do I need the last else statement? Isnt
the
result of $mail-Send() completed if I only check for !$mail-Send()?
[/snip]

This is fairly standard in programming languages all the way around. The
'else', even if a dummy, is the antithesis of the NOT statement. Think
of it this way ...

my code
if($mail-Send()){
// sends mail because $mail-Send evaluates to TRUE
} else {
// evaluates to FALSE
echo $lang_error['mailer_error'] . br\n;
}
my code

your code
my comments
if(!$mail-Send()) {
// if $mail-Send is FALSE 'if' evaluates TRUE
  echo $lang_error['mailer_error'] . br\n;
   } else {
// $mail-Send evaluated to TRUE, without 'else' it is has no
place to 'act'
  // Why do I need this one???
   }
your code

I hope that helps, may not be crystal clear.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Kim Steinhaug
Thanks for your reply, it all seems logical when you think of it,
still I also think it sounds logical without the extra ELSE statement
since the function has to executed for the first IF to do the comparison,
meaning that the email should be sendt in the first place. (If it didnt
how could it state FALSE or TRUE, unless PHP only simulates the
function if it falls outside the initial IF statement)

However, no reason to argue the obvious, :D

On the other hand, this would also mean that the exmaples from
phpmailers homepage are wrong :

[ SNIP FROM http://phpmailer.sourceforge.net/extending.html ]
$mail-Body= $body;
$mail-AltBody = $text_body;
$mail-AddAddress($row[email], $row[full_name]);
$mail-AddStringAttachment($row[photo], YourPhoto.jpg);

if(!$mail-Send())
echo There has been a mail error sending to  . $row[email] .
br;
[ /SNIP]

This is probably why I in the first place removed the extra ELSE statement,
since I didnt see any reason for it. But in future Ill always include it it
seems, :D

-- 

Kim Steinhaug
-
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
-
www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com
-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Paul Fierro
On 08/11/2004 9:28 AM, Kim Steinhaug [EMAIL PROTECTED] wrote:

 Thanks for your reply, it all seems logical when you think of it,
 still I also think it sounds logical without the extra ELSE statement
 since the function has to executed for the first IF to do the comparison,
 meaning that the email should be sendt in the first place. (If it didnt
 how could it state FALSE or TRUE, unless PHP only simulates the
 function if it falls outside the initial IF statement)
 
 However, no reason to argue the obvious, :D
 
 On the other hand, this would also mean that the exmaples from
 phpmailers homepage are wrong :
 
 [ SNIP FROM http://phpmailer.sourceforge.net/extending.html ]
 $mail-Body= $body;
 $mail-AltBody = $text_body;
 $mail-AddAddress($row[email], $row[full_name]);
 $mail-AddStringAttachment($row[photo], YourPhoto.jpg);
 
 if(!$mail-Send())
 echo There has been a mail error sending to  . $row[email] .
 br;
 [ /SNIP]
 
 This is probably why I in the first place removed the extra ELSE statement,
 since I didnt see any reason for it. But in future Ill always include it it
 seems, :D

I've been using PHPMailer like this for years:

if (!$mail-Send()) { }

You shouldn't need an extra else { }, Jay's reasoning nonetheless. That
being said, I don't know why it isn't working for you.

Paul

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Michael Sims
Kim Steinhaug wrote:
[snip]
 For some reason the above results in a blank mail, no $body at all,
 rest is fine. However, if I include a dummy for if all goes well :

if(!$mail-Send()) {
   echo $lang_error['mailer_error'] . br\n;
} else {
   // Why do I need this one???
}

 What I dont understand is why do I need the last else statement?

You shouldn't.

 Isnt
 the result of $mail-Send() completed if I only check for
 !$mail-Send()?

Yes.

 Maby it would be better to write like this :
if(!$mail-Send()) {
   echo $lang_error['mailer_error'] . br\n;
} else if ($mail-Send()){
   // Why do I need this one???
}

 The above would in my belief send two mails, atleast my logic tells
 me that.

I'm not familiary with phpMailer, or exactly how the Send method words, but the code
above would end up calling the Send method twice.  If the Send method does in fact
send (as its name suggests) then you probably don't want to call it twice when you
intend to send the message only once. :)

[snip]
 Hope someone understand what Im wondering about here, hehe.

In PHP (and every language that I've ever used...) an if statement's expression is
evaluated regardless of whether there is an else portion, or an elseif, etc.  For
example, suppose we have a function foo() that is evaluated primarily for its side
effects, but may return either true or false to indicate if the function was
successful.  This:

if (foo()) {
  print foo() was successful!\n;
}

is functionally equivalent to this:

if (foo()) {
  print foo() was successful!\n;
} else {

}

The null else clause should have no effect whatsoever on the execution of the
script.  In fact, the following code snippets are all functionally identical:

//Version one
foo();

//Version two
if (foo()) {

}

//Version three
if (!foo()) {

} else {

}

In all three cases foo() is evaluated just once.

Something else you should be aware of:  When the expression in the if statement is a
compound expression (it contains multiple expressions), then the PHP parser uses
lazy or short-circuit evaluation.  This means that the parser only evaluates the
portions of the expression that are necessary to calculate the result of the entire
expression.  An example:

if (foo()  bar()) {
  //Do stuff
}

In the above example, foo() is evaluated first.  If foo() returns false, bar() is
not evaluated at all.  The reason is that no matter what bar()'s return value is,
the entire expression can only be false.  Since the parser has already determined
the final result, it has no need to evaluate any further terms.  Similarly:

if (foo() || bar()) {
  //Do stuff
}

In this example, bar() will not be evaluated if foo() returns true, but will be if
foo() returns false.  These are obviously simple examples, but basically the parser
only evaluates the terms that are necessary and doesn't go any further.  This can be
used as a type of flow control to have certain functions/methods called only if
another returned true or false.  For example, the following two code snippets are
functionally identical:

//Version one
if (foo()) {
  bar();
}

//Version two
if (foo()  bar()) {

}

As far as your specific problem, I suspect that there are factors at play that you
are not aware of.  Either you have run across a bug in the PHP parser itself
(unlikely), or you are inadvertently making other changes when you add the else
clause.  I would suggest using basic debugging techniques to echo/print the contents
of the body string at various points to see what it contains.  You may need to drill
down into the actual source code for the Send() method to see what it things the
body string is.  If something is happening to this value this approach should reveal
where it's occuring.

HTH...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Michael Sims
Michael Sims wrote:
 string at various points to see what it contains.  You may need to
 drill down into the actual source code for the Send() method to see
 what it things the body string is.

Errr... s/things/thinks/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Ed Lazor
Wow, Michael.  Nice response.

-Ed


 -Original Message-
 From: Michael Sims [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, August 11, 2004 9:03 AM
 To: [EMAIL PROTECTED]
 Subject: RE: [PHP] PHP logic - Whats going on here?
 
 Kim Steinhaug wrote:
 [snip]
  For some reason the above results in a blank mail, no $body at all,
  rest is fine. However, if I include a dummy for if all goes well :
 
 if(!$mail-Send()) {
echo $lang_error['mailer_error'] . br\n;
 } else {
// Why do I need this one???
 }
 
  What I dont understand is why do I need the last else statement?
 
 You shouldn't.
 
  Isnt
  the result of $mail-Send() completed if I only check for
  !$mail-Send()?
 
 Yes.
 
  Maby it would be better to write like this :
 if(!$mail-Send()) {
echo $lang_error['mailer_error'] . br\n;
 } else if ($mail-Send()){
// Why do I need this one???
 }
 
  The above would in my belief send two mails, atleast my logic tells
  me that.
 
 I'm not familiary with phpMailer, or exactly how the Send method words,
 but the code
 above would end up calling the Send method twice.  If the Send method does
 in fact
 send (as its name suggests) then you probably don't want to call it twice
 when you
 intend to send the message only once. :)
 
 [snip]
  Hope someone understand what Im wondering about here, hehe.
 
 In PHP (and every language that I've ever used...) an if statement's
 expression is
 evaluated regardless of whether there is an else portion, or an elseif,
 etc.  For
 example, suppose we have a function foo() that is evaluated primarily for
 its side
 effects, but may return either true or false to indicate if the function
 was
 successful.  This:
 
 if (foo()) {
   print foo() was successful!\n;
 }
 
 is functionally equivalent to this:
 
 if (foo()) {
   print foo() was successful!\n;
 } else {
 
 }
 
 The null else clause should have no effect whatsoever on the execution of
 the
 script.  In fact, the following code snippets are all functionally
 identical:
 
 //Version one
 foo();
 
 //Version two
 if (foo()) {
 
 }
 
 //Version three
 if (!foo()) {
 
 } else {
 
 }
 
 In all three cases foo() is evaluated just once.
 
 Something else you should be aware of:  When the expression in the if
 statement is a
 compound expression (it contains multiple expressions), then the PHP
 parser uses
 lazy or short-circuit evaluation.  This means that the parser only
 evaluates the
 portions of the expression that are necessary to calculate the result of
 the entire
 expression.  An example:
 
 if (foo()  bar()) {
   //Do stuff
 }
 
 In the above example, foo() is evaluated first.  If foo() returns false,
 bar() is
 not evaluated at all.  The reason is that no matter what bar()'s return
 value is,
 the entire expression can only be false.  Since the parser has already
 determined
 the final result, it has no need to evaluate any further terms.
 Similarly:
 
 if (foo() || bar()) {
   //Do stuff
 }
 
 In this example, bar() will not be evaluated if foo() returns true, but
 will be if
 foo() returns false.  These are obviously simple examples, but basically
 the parser
 only evaluates the terms that are necessary and doesn't go any further.
 This can be
 used as a type of flow control to have certain functions/methods called
 only if
 another returned true or false.  For example, the following two code
 snippets are
 functionally identical:
 
 //Version one
 if (foo()) {
   bar();
 }
 
 //Version two
 if (foo()  bar()) {
 
 }
 
 As far as your specific problem, I suspect that there are factors at play
 that you
 are not aware of.  Either you have run across a bug in the PHP parser
 itself
 (unlikely), or you are inadvertently making other changes when you add the
 else
 clause.  I would suggest using basic debugging techniques to echo/print
 the contents
 of the body string at various points to see what it contains.  You may
 need to drill
 down into the actual source code for the Send() method to see what it
 things the
 body string is.  If something is happening to this value this approach
 should reveal
 where it's occuring.
 
 HTH...
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Jason Wong
On Thursday 12 August 2004 01:26, Ed Lazor wrote:

 Wow, Michael.  Nice response.

Could we please trim our posts? Thank you.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Good day to let down old friends who need help.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP logic - Whats going on here?

2004-08-11 Thread Ed Lazor
 -Original Message-
  Wow, Michael.  Nice response.
 
 Could we please trim our posts? Thank you.

Sorry.  Thought I'd sent it to him only.

-Ed

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Logic problem

2004-04-20 Thread Alex Hogan
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;
}
}


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

2004-04-20 Thread John Nichel
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

2004-04-20 Thread Alex Hogan
[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

2004-04-20 Thread Alex Hogan
[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

2004-04-20 Thread Kelly Hallman
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

2004-04-20 Thread Ford, Mike [LSS]
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

2004-04-20 Thread John Nichel
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

2004-04-20 Thread Alex Hogan
 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. 
** 




[PHP] logic for displaying hierarchical data (ala windows explorer)

2003-12-15 Thread Chris W. Parker
Hi everyone,

Last Friday I struggled for a long time with displaying some data that's
stored using the Modified Preorder Tree Traversal method. Without making
this email overly long and complicated (like my first draft was) I'd
like to simply ask if someone has any links or functions or instructions
they can give me on how to display my data in such a way.

I want the following:

Level 1A
|--Level 2A
|  \--Level 3A
| |--Level 4A
| |  \--Level 5A
| \--Level 3B
|--Level 2B
|  \--Level 3C
\--Level 2C
   \--Level 3D

What I always end up with is this (or some variant of it):

Level 1A
|--Level 2A
|  \--Level 3A
|  |  |--Level 4A
|  |  |  \--Level 5A
|  |  \--Level 3B
|--Level 2B
|  \--Level 3C
\--Level 2C
|  \--Level 3D


Any help is appreciated.

Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] MySQL query/PHP logic?

2003-07-29 Thread Petre Agenbag
Hi List
 OK, I've posted this on the MySQL list as well, but it seems a bit quiet
there, and arguably it could definately be a PHP rather than mysql question
depending on whether it can be done with one query (then it was/is a mysql
query), or whether it should be done with some structures and multiple
queries ( then it's arguably PHP).

So, here goes.


I'm trying to return from multiple tables, the records that have field
information_sent between two dates.
The tables are all related by means of the id of the entry in the main
table, ie..

main
id  entity_name ...

fof
id_fof  id  information_sent ...

pub
id_pub  id  information_sent ...

etc.

So, I tried the following join

select * from main
left join fof on main.id = fof.id
left join pub on main.id = pub.id
left join gov on main.id = gov.id
left join med on main.id = med.id
left join ngo on main.id = ngo.id
left join own on main.id = own.id
left join sup on main.id = sup.id
left join tra on main.id = tra.id
where (
(fof.information_sent  '$date1' and fof.information_sent  '$date2')
OR
(pub.information_sent  '$date1' and pub.information_sent  '$date2')
OR
(gov.information_sent  '$date1' and gov.information_sent  '$date2')
OR
(med.information_sent  '$date1' and med.information_sent  '$date2')
OR
(ngo.information_sent  '$date1' and ngo.information_sent  '$date2')
OR
(own.information_sent  '$date1' and own.information_sent  '$date2')
OR
(sup.information_sent  '$date1' and sup.information_sent  '$date2')
OR
(tra.information_sent  '$date1' and tra.information_sent  '$date2')
)
order by entity_name


BUT, although it seems to be joining the tables correctly AND only
returning the ones with the correct date criteria, it does NOT return
the id or the information_sent fields correctly ( due to duplication
in the result )

Can this be done in one query without sub-selects, or should it be broken up
(in which case I would still need help with the logic and to minimize the
amount of queries inside loops)


Thanks



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] MySQL query/PHP logic?

2003-07-29 Thread Jennifer Goodie
 select * from main
   left join fof on main.id = fof.id
   left join pub on main.id = pub.id
   left join gov on main.id = gov.id
   left join med on main.id = med.id
   left join ngo on main.id = ngo.id
   left join own on main.id = own.id
   left join sup on main.id = sup.id
[snip]
 BUT, although it seems to be joining the tables correctly AND only
 returning the ones with the correct date criteria, it does NOT return
 the id or the information_sent fields correctly ( due to duplication
 in the result )

 Can this be done in one query without sub-selects, or should it
 be broken up
 (in which case I would still need help with the logic and to minimize the
 amount of queries inside loops)


Instead of select * list out the fields you want to select and alias the
duplicates, for example

select fof.id as fof_id, pub.id as pub_id, gov.id as gov_id etc.

Then when you do you mysql_fetch_array the indexes will be the aliases you
gave the columns so nothing will get overwritten.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] MySQL query/PHP logic?

2003-07-29 Thread Nicholas Robinson
Don't know whether it's just because it's late at night here in the UK or 
whether I'm being a bit dim, but wouldn't it be much, much easier to store 
all the data in your non-main tables in a single table and distinguish the 
type of data (i.e. fof, pub, gov, etc) by a field. This would simplify 
your query and no doubt improve performance.


On Tuesday 29 Jul 2003 10:13 pm, Petre Agenbag wrote:
 Hi List
  OK, I've posted this on the MySQL list as well, but it seems a bit quiet
 there, and arguably it could definately be a PHP rather than mysql question
 depending on whether it can be done with one query (then it was/is a mysql
 query), or whether it should be done with some structures and multiple
 queries ( then it's arguably PHP).

 So, here goes.


 I'm trying to return from multiple tables, the records that have field
 information_sent between two dates.
 The tables are all related by means of the id of the entry in the main
 table, ie..

 main
 identity_name ...

 fof
 id_fofid  information_sent ...

 pub
 id_pubid  information_sent ...

 etc.

 So, I tried the following join

 select * from main
   left join fof on main.id = fof.id
   left join pub on main.id = pub.id
   left join gov on main.id = gov.id
   left join med on main.id = med.id
   left join ngo on main.id = ngo.id
   left join own on main.id = own.id
   left join sup on main.id = sup.id
   left join tra on main.id = tra.id
   where (
   (fof.information_sent  '$date1' and fof.information_sent  '$date2')
   OR
   (pub.information_sent  '$date1' and pub.information_sent  '$date2')
   OR
   (gov.information_sent  '$date1' and gov.information_sent  '$date2')
   OR
   (med.information_sent  '$date1' and med.information_sent  '$date2')
   OR
   (ngo.information_sent  '$date1' and ngo.information_sent  '$date2')
   OR
   (own.information_sent  '$date1' and own.information_sent  '$date2')
   OR
   (sup.information_sent  '$date1' and sup.information_sent  '$date2')
   OR
   (tra.information_sent  '$date1' and tra.information_sent  '$date2')
   )
   order by entity_name


 BUT, although it seems to be joining the tables correctly AND only
 returning the ones with the correct date criteria, it does NOT return
 the id or the information_sent fields correctly ( due to duplication
 in the result )

 Can this be done in one query without sub-selects, or should it be broken
 up (in which case I would still need help with the logic and to minimize
 the amount of queries inside loops)


 Thanks


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] MySQL query/PHP logic?

2003-07-29 Thread Jim Lucas
Try something like this.

select
  fof.id AS fof_id, fof.information_sent AS fof_info,
  pub.id AS pub_id, pub.information_sent AS pub_info,
  gov.id AS gov_id, gov.information_sent AS gov_info,
  med.id AS med_id, med.information_sent AS med_info,
  ngo.id AS ngo_id, ngo.information_sent AS ngo_info,
  own.id AS own_id, own.information_sent AS own_info,
  sup.id AS sup_id, sup.information_sent AS tup_info,
  tra.id AS tra_id, tra.information_sent AS tra_info,
from main
 left join fof on main.id = fof.id
 left join pub on main.id = pub.id
 left join gov on main.id = gov.id
 left join med on main.id = med.id
 left join ngo on main.id = ngo.id
 left join own on main.id = own.id
 left join sup on main.id = sup.id
 left join tra on main.id = tra.id
where (
 (fof.information_sent  '$date1' and fof.information_sent  '$date2')
 OR
 (pub.information_sent  '$date1' and pub.information_sent  '$date2')
 OR
 (gov.information_sent  '$date1' and gov.information_sent  '$date2')
 OR
 (med.information_sent  '$date1' and med.information_sent  '$date2')
 OR
 (ngo.information_sent  '$date1' and ngo.information_sent  '$date2')
 OR
 (own.information_sent  '$date1' and own.information_sent  '$date2')
 OR
 (sup.information_sent  '$date1' and sup.information_sent  '$date2')
 OR
 (tra.information_sent  '$date1' and tra.information_sent  '$date2')
 )
order by entity_name

then in your loop you will need to look for something like this.

while($row = mysql_fetch_array($results)){
  if(!empty($row['fof_id']))
   echo found;
  if(!empty($row['fof_id']))
   echo found;
  etc...
}

You get my point,  but the big part is the select *  -- part of the sql
call

you have to identify each column that you want back with an alias otherwise
they stomp all over one another.

Jim Lucas

- Original Message -
From: Petre Agenbag [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, July 29, 2003 2:13 PM
Subject: [PHP] MySQL query/PHP logic?


 Hi List
  OK, I've posted this on the MySQL list as well, but it seems a bit quiet
 there, and arguably it could definately be a PHP rather than mysql
question
 depending on whether it can be done with one query (then it was/is a mysql
 query), or whether it should be done with some structures and multiple
 queries ( then it's arguably PHP).

 So, here goes.


 I'm trying to return from multiple tables, the records that have field
 information_sent between two dates.
 The tables are all related by means of the id of the entry in the main
 table, ie..

 main
 id entity_name ...

 fof
 id_fof id information_sent ...

 pub
 id_pub id information_sent ...

 etc.

 So, I tried the following join

 select * from main
 left join fof on main.id = fof.id
 left join pub on main.id = pub.id
 left join gov on main.id = gov.id
 left join med on main.id = med.id
 left join ngo on main.id = ngo.id
 left join own on main.id = own.id
 left join sup on main.id = sup.id
 left join tra on main.id = tra.id
 where (
 (fof.information_sent  '$date1' and fof.information_sent  '$date2')
 OR
 (pub.information_sent  '$date1' and pub.information_sent  '$date2')
 OR
 (gov.information_sent  '$date1' and gov.information_sent  '$date2')
 OR
 (med.information_sent  '$date1' and med.information_sent  '$date2')
 OR
 (ngo.information_sent  '$date1' and ngo.information_sent  '$date2')
 OR
 (own.information_sent  '$date1' and own.information_sent  '$date2')
 OR
 (sup.information_sent  '$date1' and sup.information_sent  '$date2')
 OR
 (tra.information_sent  '$date1' and tra.information_sent  '$date2')
 )
 order by entity_name


 BUT, although it seems to be joining the tables correctly AND only
 returning the ones with the correct date criteria, it does NOT return
 the id or the information_sent fields correctly ( due to duplication
 in the result )

 Can this be done in one query without sub-selects, or should it be broken
up
 (in which case I would still need help with the logic and to minimize the
 amount of queries inside loops)


 Thanks



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Logic headache, please help.

2002-11-11 Thread Tony Crockford
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




Re: [PHP] Logic headache, please help.

2002-11-11 Thread Marco Tabini
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.

2002-11-11 Thread Tony Crockford




 -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.

2002-11-11 Thread Marco Tabini
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

2002-06-04 Thread Analysis Solutions

On Tue, Jun 04, 2002 at 04:40:26AM +0400, Ricardo Fitzgerald wrote:
 
 I'm trying to echo a neat table

I've GOT to bust your chops.  That table and your code are anything BUT 
neat.  For neat, you need to put /td tags to close each cell.  Also 
nest your code properly...

   if ($value2 ==0) {
  echo td$variable1;
   }

as opposed to 

   if ($value2 ==0) {
   echo td$variable1;
   }


Now, to the logic problems in your code.  Please note, I've snipped a 
LOT...

 //Value1 is always 1 
 if ($value1 == 0)
 {
 exit
 }

So, if the value is always 1 why bother even doing the test?


 if ($value2 ==0)
 {
 .td ... $variable1 ... 
 }

 if($value2 == 0)
 {
 .td ... $variable1 ... 
 .tr  /next row
 .td ... $variable5 ... 
 }

Dude, you're evaluating if $value2 == 0 twice and thus printing the same 
stuff twice.


 if($value3 == 3)
 {
 .td ... $variable1 ... 
 .tr  /next row
 .td ... $variable5 ... 
 ./tr
 .td ... $variable9 ... 

Now, if $value3 == 3 you're going ahead and printing out variable1 and 5 
all over again.  Am I correct in assuming that if value3 == 3 all you 
want to print is variable9 and up?  If so, then just print that.

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Logic -- conditional statements

2002-06-04 Thread Ricardo Fitzgerald

Hi to all,

I'm trying to echo a neat table with values from a form, depending on
the values it echoes a table with one row with two or with three:
Then I have conditional nested statements, to validate these variables
and wrote the table with the proper values in each case, the problem
is the table is displayed 3 times instead of 1 each time it finds a
value TRUE!

I need it to display only once, I mean in the first instance the
table, has 1 row, the second 2 rows, the third 3 rows, and they are
independent.

The code is something like:
//Value1 is always 1 
if ($value1 == 0)
{
exit
}
if ($value2 ==0)
{
echo // echoes the table
.
.  
.td ... $variable1 ... 
.td ... $variable2... 
.td ... $variable3 ... 
.td ... $variable4 ... 

}
if($value2 == 0)
{

.
.  
echo // echoes the table
.
.  
.td ... $variable1 ... 
.td ... $variable2... 
.td ... $variable3 ... 
.td ... $variable4 ... 

.tr  /next row
.  
.td ... $variable5 ... 
.td ... $variable6... 
.td ... $variable7 ... 
.td ... $variable8 ... 
./tr
.
.
}
if($value3 == 3)
{
  
.
.  
echo // echoes the table
.
.  
.td ... $variable1 ... 
.td ... $variable2... 
.td ... $variable3 ... 
.td ... $variable4 ... 

.tr  /next row
.  
.td ... $variable5 ... 
.td ... $variable6... 
.td ... $variable7 ... 
.td ... $variable8 ... 
./tr
.
.  
.td ... $variable9 ... 
.td ... $variable10... 
.td ... $variable11 ... 
.td ... $variable12 ... 
./tr
.
.
//and then closes the php script, 

TIA

Regards,

Rick

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Logic -- conditional statements

2002-06-04 Thread Naintara Jain

The problem here is that you have defined three different variables
$value1,$value2,$value3.

Keep only one variable (say,$valueChk) that can take values 1,2 or 3.
Then check for the condition.
And there's another mistake in the script, you are checking
---if ($value2 ==0)---
twice, you probably mean to check for $value1 ==1 (for the first of the
$value2 ==0 checks).

Once you are through with these changes, your script will work perfectly.
And if you feel like improving it you need not repeat the td statements.
You can merely append the additional rows depending on the value of the
variable you set (say, $valueChk).

the following isn't the actual script, but mainly the logic.

$table=table
if($valueChk==0)
exit
if($valueChk==1)
{
//.append the first TRTD statement to $table variable
$table .= TRTD ;

}

if($valueChk==2)
{
//.append the second TRTD statement to $table variable
}

if($valueChk==3)
{
//.append the third TRTD statement to $table variable
}

//now close the table tag and echo the $table variable

you'll get the table with the desired number of rows.

-Naintara

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
t]On Behalf Of Ricardo Fitzgerald
Sent: Friday, July 10, 2893 3:44 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Logic -- conditional statements


Hi to all,

I'm trying to echo a neat table with values from a form, depending on
the values it echoes a table with one row with two or with three:
Then I have conditional nested statements, to validate these variables
and wrote the table with the proper values in each case, the problem
is the table is displayed 3 times instead of 1 each time it finds a
value TRUE!

I need it to display only once, I mean in the first instance the
table, has 1 row, the second 2 rows, the third 3 rows, and they are
independent.

The code is something like:
//Value1 is always 1
if ($value1 == 0)
{
exit
}
if ($value2 ==0)
{
echo // echoes the table
.
.
.td ... $variable1 ...
.td ... $variable2...
.td ... $variable3 ...
.td ... $variable4 ...

}
if($value2 == 0)
{

.
.
echo // echoes the table
.
.
.td ... $variable1 ...
.td ... $variable2...
.td ... $variable3 ...
.td ... $variable4 ...

.tr  /next row
.
.td ... $variable5 ...
.td ... $variable6...
.td ... $variable7 ...
.td ... $variable8 ...
./tr
.
.
}
if($value3 == 3)
{

.
.
echo // echoes the table
.
.
.td ... $variable1 ...
.td ... $variable2...
.td ... $variable3 ...
.td ... $variable4 ...

.tr  /next row
.
.td ... $variable5 ...
.td ... $variable6...
.td ... $variable7 ...
.td ... $variable8 ...
./tr
.
.
.td ... $variable9 ...
.td ... $variable10...
.td ... $variable11 ...
.td ... $variable12 ...
./tr
.
.
//and then closes the php script,

TIA

Regards,

Rick

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




FW: [PHP] Logic -- conditional statements

2002-06-04 Thread Naintara Jain

One correction, Ricardo

for appending the rows, you will have to change the condition

//for 1st row
if($valueChk = 1  $valueChk = 3)

//for 2nd row
if($valueChk = 2  $valueChk = 3)

//for 3rd row
if($valueChk == 3)



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
t]On Behalf Of Naintara Jain
Sent: Tuesday, June 04, 2002 2:37 PM
To: Ricardo Fitzgerald; [EMAIL PROTECTED]
Subject: RE: [PHP] Logic -- conditional statements


The problem here is that you have defined three different variables
$value1,$value2,$value3.

Keep only one variable (say,$valueChk) that can take values 1,2 or 3.
Then check for the condition.
And there's another mistake in the script, you are checking
---if ($value2 ==0)---
twice, you probably mean to check for $value1 ==1 (for the first of the
$value2 ==0 checks).

Once you are through with these changes, your script will work perfectly.
And if you feel like improving it you need not repeat the td statements.
You can merely append the additional rows depending on the value of the
variable you set (say, $valueChk).

the following isn't the actual script, but mainly the logic.

$table=table
if($valueChk==0)
exit
if($valueChk==1)
{
//.append the first TRTD statement to $table variable
$table .= TRTD ;

}

if($valueChk==2)
{
//.append the second TRTD statement to $table variable
}

if($valueChk==3)
{
//.append the third TRTD statement to $table variable
}

//now close the table tag and echo the $table variable

you'll get the table with the desired number of rows.

-Naintara

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
t]On Behalf Of Ricardo Fitzgerald
Sent: Friday, July 10, 2893 3:44 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Logic -- conditional statements


Hi to all,

I'm trying to echo a neat table with values from a form, depending on
the values it echoes a table with one row with two or with three:
Then I have conditional nested statements, to validate these variables
and wrote the table with the proper values in each case, the problem
is the table is displayed 3 times instead of 1 each time it finds a
value TRUE!

I need it to display only once, I mean in the first instance the
table, has 1 row, the second 2 rows, the third 3 rows, and they are
independent.

The code is something like:
//Value1 is always 1
if ($value1 == 0)
{
exit
}
if ($value2 ==0)
{
echo // echoes the table
.
.
.td ... $variable1 ...
.td ... $variable2...
.td ... $variable3 ...
.td ... $variable4 ...

}
if($value2 == 0)
{

.
.
echo // echoes the table
.
.
.td ... $variable1 ...
.td ... $variable2...
.td ... $variable3 ...
.td ... $variable4 ...

.tr  /next row
.
.td ... $variable5 ...
.td ... $variable6...
.td ... $variable7 ...
.td ... $variable8 ...
./tr
.
.
}
if($value3 == 3)
{

.
.
echo // echoes the table
.
.
.td ... $variable1 ...
.td ... $variable2...
.td ... $variable3 ...
.td ... $variable4 ...

.tr  /next row
.
.td ... $variable5 ...
.td ... $variable6...
.td ... $variable7 ...
.td ... $variable8 ...
./tr
.
.
.td ... $variable9 ...
.td ... $variable10...
.td ... $variable11 ...
.td ... $variable12 ...
./tr
.
.
//and then closes the php script,

TIA

Regards,

Rick

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Logic -- conditional statements

2002-06-04 Thread John Holmes

Switches come in handy here...

Switch($valueChk)
{
  case 1:
do_whatever1();
  case 2:
do_whatever2();
  case 3:
do_whatever3();
break;
}

If the variable is 1, then all three functions will be called. 

I don't remember what the original question was or if this even applies,
but it's a better solution than all of the IFs that was just posted...

---John Holmes...

 -Original Message-
 From: Naintara Jain [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, June 04, 2002 5:47 PM
 To: Ricardo Fitzgerald
 Cc: Php-General@Lists. Php. Net
 Subject: FW: [PHP] Logic -- conditional statements
 
 One correction, Ricardo
 
 for appending the rows, you will have to change the condition
 
 //for 1st row
 if($valueChk = 1  $valueChk = 3)
 
 //for 2nd row
 if($valueChk = 2  $valueChk = 3)
 
 //for 3rd row
 if($valueChk == 3)
 
 
 
 -Original Message-
 From:
[EMAIL PROTECTED]

[mailto:[EMAIL PROTECTED]
 t]On Behalf Of Naintara Jain
 Sent: Tuesday, June 04, 2002 2:37 PM
 To: Ricardo Fitzgerald; [EMAIL PROTECTED]
 Subject: RE: [PHP] Logic -- conditional statements
 
 
 The problem here is that you have defined three different variables
 $value1,$value2,$value3.
 
 Keep only one variable (say,$valueChk) that can take values 1,2 or 3.
 Then check for the condition.
 And there's another mistake in the script, you are checking
 ---if ($value2 ==0)---
 twice, you probably mean to check for $value1 ==1 (for the first of
the
 $value2 ==0 checks).
 
 Once you are through with these changes, your script will work
perfectly.
 And if you feel like improving it you need not repeat the td
statements.
 You can merely append the additional rows depending on the value of
the
 variable you set (say, $valueChk).
 
 the following isn't the actual script, but mainly the logic.
 
 $table=table
 if($valueChk==0)
 exit
 if($valueChk==1)
 {
 //.append the first TRTD statement to $table variable
 $table .= TRTD ;
 
 }
 
 if($valueChk==2)
 {
 //.append the second TRTD statement to $table variable
 }
 
 if($valueChk==3)
 {
 //.append the third TRTD statement to $table variable
 }
 
 //now close the table tag and echo the $table variable
 
 you'll get the table with the desired number of rows.
 
 -Naintara
 
 -Original Message-
 From:
[EMAIL PROTECTED]

[mailto:[EMAIL PROTECTED]
 t]On Behalf Of Ricardo Fitzgerald
 Sent: Friday, July 10, 2893 3:44 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Logic -- conditional statements
 
 
 Hi to all,
 
 I'm trying to echo a neat table with values from a form, depending on
 the values it echoes a table with one row with two or with three:
 Then I have conditional nested statements, to validate these variables
 and wrote the table with the proper values in each case, the problem
 is the table is displayed 3 times instead of 1 each time it finds a
 value TRUE!
 
 I need it to display only once, I mean in the first instance the
 table, has 1 row, the second 2 rows, the third 3 rows, and they are
 independent.
 
 The code is something like:
 //Value1 is always 1
 if ($value1 == 0)
 {
 exit
 }
 if ($value2 ==0)
 {
 echo // echoes the table
 .
 .
 .td ... $variable1 ...
 .td ... $variable2...
 .td ... $variable3 ...
 .td ... $variable4 ...
 
 }
 if($value2 == 0)
 {
 
 .
 .
 echo // echoes the table
 .
 .
 .td ... $variable1 ...
 .td ... $variable2...
 .td ... $variable3 ...
 .td ... $variable4 ...
 
 .tr  /next row
 .
 .td ... $variable5 ...
 .td ... $variable6...
 .td ... $variable7 ...
 .td ... $variable8 ...
 ./tr
 .
 .
 }
 if($value3 == 3)
 {
 
 .
 .
 echo // echoes the table
 .
 .
 .td ... $variable1 ...
 .td ... $variable2...
 .td ... $variable3 ...
 .td ... $variable4 ...
 
 .tr  /next row
 .
 .td ... $variable5 ...
 .td ... $variable6...
 .td ... $variable7 ...
 .td ... $variable8 ...
 ./tr
 .
 .
 .td ... $variable9 ...
 .td ... $variable10...
 .td ... $variable11 ...
 .td ... $variable12 ...
 ./tr
 .
 .
 //and then closes the php script,
 
 TIA
 
 Regards,
 
 Rick
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 ---
 Incoming mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002
 
 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 ---
 Incoming mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002
 
 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

[PHP] Logic

2001-12-04 Thread Dan McCullough

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.

=
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

2001-12-04 Thread Richard S. Crawford

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

2001-12-04 Thread Dan McCullough

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

2001-12-04 Thread Martin Towell

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

2001-12-04 Thread Steve Werby

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]




[PHP] Logic/method question...

2001-10-22 Thread Jeff Lewis

It's not really, but kind of, a PHP question.  I mean it is being written in PHP :)

I am putting together a search feature for our classified ads and there are about 4000 
each day.  Now I am bulding a query to search by newspaper, date, and keywords.  One 
last thing is categories.

Curious how others would handle this...on the search screen (and on the site) we have 
broken down the classified codes into about 8-10 main groups (stuff like Merchandise, 
Transportation, Services etc).

Now the problem is this: in the database, each ad goes in with it's class code which 
matches up with the actual category.  So instead of just Merchandise we have sub 
categories like Christmas Trees.

There are close to 1500 class codeas and when I build this I need to allow the user to 
select just one of the 8-10 codes and have the program return everything.

Will I need to do something like:

if $selection=Merchandise then 
{
select all ads where code=2 AND code=5 AND code=123 AND code=567  etc etc
}

Jeff



[PHP]logic question

2001-07-22 Thread Chris Cocuzzo

hey-

I'm in the process of writing a links page for a website. I want to have all
the links seperated by category, and those categories would be placed in
different columns. This means also that different categories of links could
be on the same row in the table used to lay it all out. i'm pulling the
category out of the mysql db, does anyone have an example i can look at on
how I might go about doing this??

chris


-- 
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

2001-07-22 Thread rm

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]




[PHP] logic question concerning sale prices in shopping basket app

2001-02-28 Thread Brett

I have a simple page that offers three items(7700,7701,7702).  I am trying to figure 
the best way to calculate the price for each shirt depending on the amount they want.  
The breakdown of prices is:
Any 3 shirts for $50
7700 - 3 for $33 or $14.99
7701  7702 - 3 for $50 or $25.

So I sort through the 7700's and set the price for multiples of three which is 11, 
then sort through the 7701 and 7702 and set the price for multiples of three which is 
16.66.

Now I run into a problem with the remaining shirts and figuring out how they should be 
priced.  If there are four shirts left and they are  2-7700, 1- 7701, and 1- 7702,
I need a way to make sure that the 7701 and 7702 are included with 1 of the 7700, and 
the other 7700 is priced at 14.99.

The items are stored in mysql and referenced by the product code(7700).  Hopefully I 
explained this weel enough.  Maybe some ofyou have an idea.
If you want to see what this is for go to http://www.jnewman.com/oxfords.  Play all 
you want, it does nothing but add the prices.  If you add 1 buttondown and 2 of the 
other shirts you will see that the total is 70 something instead of 50 something.

Thanks,
Brett