Re: [PHP] logic operands problem
Devendra Jadhav wrote: what do you think about this? if( ! (page == 1 page == 2)){ //here } Well a simple (and) does not help. I want to have all results that contain either page = 1 OR page = 3, AND in the same time I want to have the results that contain page=2 OR page= 3 , But the result should never contain page = 1 and page = 2 in the same time. Any further idea? On Mon, Dec 7, 2009 at 4:22 PM, Merlin Morgenstern merli...@fastmail.fm mailto:merli...@fastmail.fm wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Devendra Jadhav देवेंद्र जाधव
[PHP] Re: logic operands problem
I think you could use another braket on the second example: ((page== 1 OR page== 3) AND page!= 2) OR ((page== 2 OR page== 3) AND page != 1) Other than that I don't think I can help. How come the page can be 1 or 3, but not 2? I think you could change the logic, but I don't have enough info about your code. If page is 1 or 3, it won't be 2 (obviously), but why 2 or 3 is acceptable? Merlin Morgenstern merli...@fastmail.fm wrote in message news:8e.77.13248.a9edc...@pb1.pair.com... 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
[PHP] Re: logic operands problem
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 Surely what you need is xor (exclusive-or) I can't believe a programmer has never heard of that! (page==1 XOR page==2) AND page==3 -- Peter Ford phone: 01580 89 Developer fax: 01580 893399 Justcroft International Ltd., Staplehurst, Kent -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic operands problem
On Mon, 2009-12-07 at 11:52 +0100, Merlin Morgenstern wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin I thought this might work: (page = 3) OR (page = 1 XOR 2) But having given it more thought, I'm not so sure. I assume from your example that this is MySQL code and not PHP. Having said that, how can a field of one row have more than one value? Surely `page` is either 1, 2 or 3, not two of them at once. How do you want your results pulled? Assuming you have rows containing all three values, how do you decide which of the pair of results you want? Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] Re: logic operands problem
Peter Ford wrote: 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 Surely what you need is xor (exclusive-or) I can't believe a programmer has never heard of that! (page==1 XOR page==2) AND page==3 HEllo Peter, thank you for your reply. I know about XOR, but unfortunatelly I might not know how to use it properly OR it is not aplicable on SQL. I am trying to retrive data: SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) I know this is not php, but I thought the logic should be the same in this case?! Regards, Merlin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: logic operands problem
On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote: Peter Ford wrote: 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 Surely what you need is xor (exclusive-or) I can't believe a programmer has never heard of that! (page==1 XOR page==2) AND page==3 HEllo Peter, thank you for your reply. I know about XOR, but unfortunatelly I might not know how to use it properly OR it is not aplicable on SQL. I am trying to retrive data: SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) I know this is not php, but I thought the logic should be the same in this case?! Regards, Merlin This will likely retrieve all the records in the table. Is that what your tests have shown? Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Re: logic operands problem
I don't really get it. This is a select statement working with the datas of one table. A field of a record (namely page here) can only take one value, so it is totally nonsense to give XOR for that field. I think you want to select two different recordsets: one with page 1 and 3, and another with 2 and 3, am I right? SanTa - Original Message - From: Ashley Sheridan a...@ashleysheridan.co.uk To: Merlin Morgenstern merli...@fastmail.fm Cc: Peter Ford p...@justcroft.com; php-general@lists.php.net Sent: Monday, December 07, 2009 12:39 PM Subject: Re: [PHP] Re: logic operands problem On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote: Peter Ford wrote: 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 Surely what you need is xor (exclusive-or) I can't believe a programmer has never heard of that! (page==1 XOR page==2) AND page==3 HEllo Peter, thank you for your reply. I know about XOR, but unfortunatelly I might not know how to use it properly OR it is not aplicable on SQL. I am trying to retrive data: SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) I know this is not php, but I thought the logic should be the same in this case?! Regards, Merlin This will likely retrieve all the records in the table. Is that what your tests have shown? 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
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] Re: logic operands problem
Ashley Sheridan wrote: On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote: Peter Ford wrote: 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 Surely what you need is xor (exclusive-or) I can't believe a programmer has never heard of that! (page==1 XOR page==2) AND page==3 HEllo Peter, thank you for your reply. I know about XOR, but unfortunatelly I might not know how to use it properly OR it is not aplicable on SQL. I am trying to retrive data: SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) I know this is not php, but I thought the logic should be the same in this case?! Regards, Merlin This will likely retrieve all the records in the table. Is that what your tests have shown? Thanks, Ash http://www.ashleysheridan.co.uk Exactly! This is unfortunatelly what happens! Any ideas how to get the correct results?
Re: [PHP] Re: logic operands problem
Sándor Tamás (HostWare Kft.) wrote: I don't really get it. This is a select statement working with the datas of one table. A field of a record (namely page here) can only take one value, so it is totally nonsense to give XOR for that field. I think you want to select two different recordsets: one with page 1 and 3, and another with 2 and 3, am I right? SanTa Yes, you are right. Any ideas on how to do this within one query? - Original Message - From: Ashley Sheridan a...@ashleysheridan.co.uk To: Merlin Morgenstern merli...@fastmail.fm Cc: Peter Ford p...@justcroft.com; php-general@lists.php.net Sent: Monday, December 07, 2009 12:39 PM Subject: Re: [PHP] Re: logic operands problem On Mon, 2009-12-07 at 12:37 +0100, Merlin Morgenstern wrote: Peter Ford wrote: 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 Surely what you need is xor (exclusive-or) I can't believe a programmer has never heard of that! (page==1 XOR page==2) AND page==3 HEllo Peter, thank you for your reply. I know about XOR, but unfortunatelly I might not know how to use it properly OR it is not aplicable on SQL. I am trying to retrive data: SELECT * FROM test WHERE ((page = 1 XOR page = 2) OR page = 3) I know this is not php, but I thought the logic should be the same in this case?! Regards, Merlin This will likely retrieve all the records in the table. Is that what your tests have shown? Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] logic operands problem
On Mon, 2009-12-07 at 12:49 +0100, Merlin Morgenstern wrote: Ashley Sheridan wrote: On Mon, 2009-12-07 at 11:52 +0100, Merlin Morgenstern wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin I thought this might work: (page = 3) OR (page = 1 XOR 2) But having given it more thought, I'm not so sure. I assume from your example that this is MySQL code and not PHP. Having said that, how can a field of one row have more than one value? Surely `page` is either 1, 2 or 3, not two of them at once. How do you want your results pulled? Assuming you have rows containing all three values, how do you decide which of the pair of results you want? Thanks, Ash http://www.ashleysheridan.co.uk You have described the problem very well. This is exactly where I can not find a solution. the page number translates to the following: 1= first page 2= following pages 3= all pages This are the options a user has while booking a product on my site. Now if ther is a new client that wants to book all pages, I need to query the table to find out if the spot is available. The spot would be full if page 1 has more results then 3 , OR all following pages have more then 3 results. So to find out if all pages option would be available I need to query the db to retrieve all results, that are (page = 3) OR (page = 1 XOR 2) Am I wrong? I'm pretty confused by your logic, but I think the only way you can achieve what you want is with multiple queries and counts. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] logic operands problem
Merlin Morgenstern wrote: You have described the problem very well. This is exactly where I can not find a solution. the page number translates to the following: 1= first page 2= following pages 3= all pages This are the options a user has while booking a product on my site. Now if ther is a new client that wants to book all pages, I need to query the table to find out if the spot is available. The spot would be full if page 1 has more results then 3 , OR all following pages have more then 3 results. So to find out if all pages option would be available I need to query the db to retrieve all results, that are (page = 3) OR (page = 1 XOR 2) Am I wrong? Yes I think you are! And XOR may be wrong here. XOR is a binary operator, so think of the number as 0b0011 for 3 0b0010 for 2 and 0b0001 for 1 ... 1 XOR 2 will give a result of 0b0011 - so = 3 What you are trying to do just seems wrong in general. 'if page 1 has more results then 3' requires you count the number of page 1 records and compare with the number of page 3 records. And the same with page 2 results. I don't think you are giving enough detail to know exactly what you are trying to achieve, but what you are describing so far does not make sense 'logically'. If you are trying to book a 'set' of pages but can't if one of that set is already booked, then I don't think you can do this with a single query. You need to check each 'page' individually. If this was room booking, then one would have to check there are no other bookings for a day in the period for that particular room. Or putting it another way, there are no days in the period when all rooms are booked, but in this case you still need to know that a particular room is available for the whole period. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: logic operands problem
-Original Message- From: Merlin Morgenstern [mailto:merli...@fastmail.fm] Sent: 07 December 2009 11:52 To: Sándor Tamás (HostWare Kft.) Cc: Merlin Morgenstern; php-general@lists.php.net Subject: Re: [PHP] Re: logic operands problem Sándor Tamás (HostWare Kft.) wrote: I don't really get it. This is a select statement working with the datas of one table. A field of a record (namely page here) can only take one value, so it is totally nonsense to give XOR for that field. I think you want to select two different recordsets: one with page 1 and 3, and another with 2 and 3, am I right? SanTa Yes, you are right. Any ideas on how to do this within one query? If you need these two specific recordsets, I don't see how you can. You'll have to make two queries and do any further logic in PHP using the two sets of results. XOR is a total nonsense in this situation -- as your condition is targeting a single, single-valued field, the value you are testing cannot possibly be simultaneously both 1 and 2, so the XOR operator is essentially redundant and effectively the same as the OR operator. This is pretty much why SQL does not offer you the XOR operator! All of the condition variants I've seen in this thread so far pretty much boil down to (page=1 OR page=2 OR page=3), which, as you found, returns your entire database. Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: logic operands problem
On Mon, 2009-12-07 at 12:26 +, Ford, Mike wrote: This is pretty much why SQL does not offer you the XOR operator! Someone better tell the MySQL developers then... http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] Live PHP Code Templates for NetBeans - accelerate your php development.
Hello Everyone, I've made a few code templates (HTML, PHP) available for everyone to download and use with NetBeans 6.7 or higher. It will greatly accelerate your php development. http://code.google.com/p/raxan/downloads/detail?name=code-templates.zipcan=2q= And if your interested in further accelerating your PHP/Ajax development, then you might want to check out the new and improved Raxan for PHP (http://raxanpdi.com/) __ Raymond Irving Raxan for PHP - Ajax just got a whole lot easier!
RE: [PHP] Re: logic operands problem
Um, yes, probably need to update my Oracle reference manuals – I think the big fat paper one on my shelf may even refer to ANSI SQL89, which I suspect is pretty much what my head content is based on also. In any case, XOR doesn’t appear to be in the latest ANSI/ISO SQL standards I have access to (ANSI 2003), so this may be a MySQL-specific extension. But however you slice it, XOR is the wrong solution for the problem at hand! ;) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Leeds Metropolitan University, C507, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: 07 December 2009 12:26 To: Ford, Mike Cc: php-general@lists.php.net Subject: RE: [PHP] Re: logic operands problem On Mon, 2009-12-07 at 12:26 +, Ford, Mike wrote: This is pretty much why SQL does not offer you the XOR operator! Someone better tell the MySQL developers then... http://dev.mysql.com/doc/refman/5.0/en/logical-operators.html Thanks, Ash http://www.ashleysheridan.co.uk To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
Re: [PHP] logic operands problem
Hey Merlin Merlin Morgenstern wrote on 2009-12-07 11:52: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? I've read the entire thread and can see that this is a MySQL query you want to make (I was about to tell you about the == comparison and the $ in a variable in PHP). What you want is all results containing 1,2 or 3, so make a WHERE page IN(1,2,3) and use PHP logic to figure out if a free slot is available or not. Or rewrite your booking routine (use data and time fields instead, maybe by creating a bunch of free slots and then a booked field with a default of 0, changed to 1 when booked) -- Kind regards Kim Emax - masterminds.dk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic operands problem
At 11:52 AM +0100 12/7/09, Merlin Morgenstern wrote: Hello everybody, I am having trouble finding a logic for following problem: Should be true if: page = 1 OR page = 3, but it should also be true if page = 2 OR page = 3 The result should never contain 1 AND 2 in the same time. This obviously does not work: (page = 1 OR page = 3) OR (page = 2 OR page = 3) This also does not work: (page = 1 OR page = 3 AND page != 2) OR (page = 2 OR page = 3 AND page != 1) Has somebody an idea how to solve this? Thank you in advance for any help! Merlin Merlin: The variable page cannot hold two values at the same time and thus your statement The result should never contain 1 AND 2 in the same time is nonsense. Now if you are working two variables, namely $a and $b and you want an algorithm to solve your problem, it's simple. if ($a + $b 3) { $result = true; } else { $result = false; } Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] logic operands problem
Hi everybody, thank you for all the help and thoughts. I have solved it, but I guess it is not an elegant solution. What I do now, is simply check again for the second case. There are 2 cases. Either first page OR all pages, second case: following pages OR all pages. My booking checking looks now as following: # on which page will the tl be placed? if ($data[page] == 3){ // all pages $where_page = 'AND (page = 1 OR page = 3)'; // unfortunatelly we have to test later on page = 2 OR page = 3. No solution inside one query. We tried also (page=1 XOR page=2) OR page = 3 $where_page_2 = 'AND (page = 2 OR page = 3)'; } else{ // page one or all following pages $where_page = 'AND page = '.$data[page]; } # find out first possible booking period do{ // get all toplistings that are at least with one day inside the desired booking period $stmt= SELECT * FROM $DB.$T54 WHERE cat_id = '$data[cat_id]' AND cat_type = '$data[cat_type]' $where_page AND ( (start_date = '$new_start' AND expires = '$new_start') OR (start_date = '$new_end' AND expires = '$new_end') OR (start_date = '$new_start' AND start_date= '$new_end') ) ; #echo $stmt.$br; $result = execute_stmt($stmt, $link); while ($row = db_get_row($result)){ $booked[start][] = $row-start_date; $booked[end][]= $row-expires; } $possible_bookings = count($booked[start]); // would there be more bookings then possible? if ($possible_bookings = $places){ // not enough space. Try nest day $shift = true; // shift period for one day $reservation = 1; $new_start = date(Ymd,strtotime($new_start. + 1 day)); $new_end = date(Ymd,strtotime($new_end. + 1 day)); } else{ // enough space unset($shift); } unset($booked); } while ($shift); // shift as long as we find free space # if client wants to book all pages, we have to try also the second constellation # we could not find a way to do this in one sql query # find out if booking period has to be shifted even further due to all pages booking if ($page == 3){ do{ // get all toplistings that are at least with one day inside the desired booking period $stmt= SELECT * FROM $DB.$T54 WHERE cat_id = '$data[cat_id]' AND cat_type = '$data[cat_type]' $where_page_2 AND ( (start_date = '$new_start' AND expires = '$new_start') OR (start_date = '$new_end' AND expires = '$new_end') OR (start_date = '$new_start' AND start_date= '$new_end') ) ; //echo $stmt.$br; $result = execute_stmt($stmt, $link); while ($row = db_get_row($result)){ $booked[start][] = $row-start_date; $booked[end][]= $row-expires; } $possible_bookings = count($booked[start]); // would there be more bookings then possible? if ($possible_bookings = $places){ // not enough space. Try nest day $shift = true; // shift period for one day $reservation = 1; $new_start = date(Ymd,strtotime($new_start. + 1 day)); $new_end = date(Ymd,strtotime($new_end. + 1 day)); } else{ // enough space unset($shift); } unset($booked); } while ($shift); // shift as long as we find free space } This is rather a dirty solution. Maybe someone has an idea on how to do it more elegant? I believe there should be one simple line that is different instead of checking it all over again for a second time. Any ideas? Kim Madsen wrote: Hey Merlin Merlin Morgenstern wrote on 2009-12-07 11:52: Hello everybody, I am
[PHP] mysterious include problem
I have been using includes for my content for a while now with no problems. Suddenly it has stopped working, and it may or may not be from some changes I made in my code structure. I use default.php for most or all of my pages within a given directory, changing the content via page numbers in the query string. So on default.php, I have the following code: ?php if(isset($_GET['page'])) { $thispage = $_GET['page']; $content = 'content/'.$_GET['page'].'.inc'; } else { $thispage = default; $content = 'content/default.inc'; } ? html, body, div etc. ?php include($content); ? I have a content subdirectory where I store all the pages with files such as default.inc, 101.inc, 102.inc, etc. As I said, this has been working fine up until now, if I use the url user/default.php or just user/ I get this error: *Warning*: include(content/.inc) [function.includehttp://lpacmarketing.hostzi.com/user/function.include]: failed to open stream: No such file or directory in * /home/a9066165/public_html/user/default.php* on line *89* AND *Warning*: include() [function.includehttp://lpacmarketing.hostzi.com/user/function.include]: Failed opening 'content/.inc' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in * /home/a9066165/public_html/user/default.php* on line *89* But if I use user/default.php?page=default I get the correct content. It's acting as if page is set, but set to NULL, and then trying to find an include at path content/.inc what's going on??
Re: [PHP] mysterious include problem
Hi Allen Allen McCabe wrote on 2009-12-07 21:03: I have been using includes for my content for a while now with no problems. Suddenly it has stopped working, and it may or may not be from some changes I made in my code structure. I use default.php for most or all of my pages within a given directory, changing the content via page numbers in the query string. So on default.php, I have the following code: ?php if(isset($_GET['page'])) { $thispage = $_GET['page']; $content = 'content/'.$_GET['page'].'.inc'; } else { $thispage = default; $content = 'content/default.inc'; } WOUW! this is a potential security issue! I can add _any_ parameter to page, incl. an external one, so skip this and use a switch instead switch($_GET['page']) { case admin: $content = content/admin.inc; break; case member: $content = content/member.inc; break; default: $content = content/default.inc; } What use is $thispage by the way? ? html, body, div etc. ?php include($content); ? I have a content subdirectory where I store all the pages with files such as default.inc, 101.inc, 102.inc, etc. As I said, this has been working fine up until now, if I use the url user/default.php or just user/ I get this error: *Warning*: include(content/.inc) $_GET['page'] is not set, try and print it to the screen aswell... [function.includehttp://lpacmarketing.hostzi.com/user/function.include]: failed to open stream: No such file or directory in * /home/a9066165/public_html/user/default.php* on line *89* AND *Warning*: include() [function.includehttp://lpacmarketing.hostzi.com/user/function.include]: Failed opening 'content/.inc' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in * /home/a9066165/public_html/user/default.php* on line *89* But if I use user/default.php?page=default I get the correct content. It's acting as if page is set, but set to NULL, and then trying to find an include at path content/.inc what's going on?? -- 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] mysterious include problem
On Mon, 2009-12-07 at 21:14 +0100, Kim Madsen wrote: Hi Allen Allen McCabe wrote on 2009-12-07 21:03: I have been using includes for my content for a while now with no problems. Suddenly it has stopped working, and it may or may not be from some changes I made in my code structure. I use default.php for most or all of my pages within a given directory, changing the content via page numbers in the query string. So on default.php, I have the following code: ?php if(isset($_GET['page'])) { $thispage = $_GET['page']; $content = 'content/'.$_GET['page'].'.inc'; } else { $thispage = default; $content = 'content/default.inc'; } WOUW! this is a potential security issue! I can add _any_ parameter to page, incl. an external one, so skip this and use a switch instead switch($_GET['page']) { case admin: $content = content/admin.inc; break; case member: $content = content/member.inc; break; default: $content = content/default.inc; } What use is $thispage by the way? ? html, body, div etc. ?php include($content); ? I have a content subdirectory where I store all the pages with files such as default.inc, 101.inc, 102.inc, etc. As I said, this has been working fine up until now, if I use the url user/default.php or just user/ I get this error: *Warning*: include(content/.inc) $_GET['page'] is not set, try and print it to the screen aswell... [function.includehttp://lpacmarketing.hostzi.com/user/function.include]: failed to open stream: No such file or directory in * /home/a9066165/public_html/user/default.php* on line *89* AND *Warning*: include() [function.includehttp://lpacmarketing.hostzi.com/user/function.include]: Failed opening 'content/.inc' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in * /home/a9066165/public_html/user/default.php* on line *89* But if I use user/default.php?page=default I get the correct content. It's acting as if page is set, but set to NULL, and then trying to find an include at path content/.inc what's going on?? -- Kind regards Kim Emax - masterminds.dk Are you sure that the paths are correct, including relative ones? Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] mysterious include problem
Instead of hard coding cases you can validate and constrain the input with a regex. Much more flexible when adding content. I would also add code to make sure the file exists, otherwise fall through to the default. On Mon, Dec 7, 2009 at 1:14 PM, Kim Madsen php@emax.dk wrote: Hi Allen Allen McCabe wrote on 2009-12-07 21:03: I have been using includes for my content for a while now with no problems. Suddenly it has stopped working, and it may or may not be from some changes I made in my code structure. I use default.php for most or all of my pages within a given directory, changing the content via page numbers in the query string. So on default.php, I have the following code: ?php if(isset($_GET['page'])) { $thispage = $_GET['page']; $content = 'content/'.$_GET['page'].'.inc'; } else { $thispage = default; $content = 'content/default.inc'; } WOUW! this is a potential security issue! I can add _any_ parameter to page, incl. an external one, so skip this and use a switch instead switch($_GET['page']) { case admin: $content = content/admin.inc; break; case member: $content = content/member.inc; break; default: $content = content/default.inc; } What use is $thispage by the way? ? html, body, div etc. ?php include($content); ? I have a content subdirectory where I store all the pages with files such as default.inc, 101.inc, 102.inc, etc. As I said, this has been working fine up until now, if I use the url user/default.php or just user/ I get this error: *Warning*: include(content/.inc) $_GET['page'] is not set, try and print it to the screen aswell... [function.includehttp://lpacmarketing.hostzi.com/user/function.include]: failed to open stream: No such file or directory in * /home/a9066165/public_html/user/default.php* on line *89* AND *Warning*: include() [function.includehttp://lpacmarketing.hostzi.com/user/function.include]: Failed opening 'content/.inc' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in * /home/a9066165/public_html/user/default.php* on line *89* But if I use user/default.php?page=default I get the correct content. It's acting as if page is set, but set to NULL, and then trying to find an include at path content/.inc what's going on?? -- Kind regards Kim Emax - masterminds.dk -- 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] Live PHP Code Templates for NetBeans - accelerate your php development.
Hi, I would like to check this out. How do you enable these code templates in NetBeans? 2009/12/8 Raymond Irving xwis...@yahoo.com Hello Everyone, I've made a few code templates (HTML, PHP) available for everyone to download and use with NetBeans 6.7 or higher. It will greatly accelerate your php development. http://code.google.com/p/raxan/downloads/detail?name=code-templates.zipcan=2q= And if your interested in further accelerating your PHP/Ajax development, then you might want to check out the new and improved Raxan for PHP (http://raxanpdi.com/) __ Raymond Irving Raxan for PHP - Ajax just got a whole lot easier!
[PHP] cookies and carts
I have a shopping cart type system set up which keeps track of the cart contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is equal to the quantity, so the name/value pair is all the information I need. But sessions are unreliable on the free server I am currently using for this website (not my choice), so I had start using cookies because users were being sporadically logged out, sometimes just on a page refresh. I want to find a way to set a cookie to remember the cart items as well, and I thought setting a cookie for each item/quantity pair was the way to go until I started trying to figure out how to unset all those cookies if the user empties their cart. Is there any way to set cookies with an array for the name? Intead of $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the SESSION?
Re: [PHP] cookies and carts
On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote: I have a shopping cart type system set up which keeps track of the cart contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is equal to the quantity, so the name/value pair is all the information I need. But sessions are unreliable on the free server I am currently using for this website (not my choice), so I had start using cookies because users were being sporadically logged out, sometimes just on a page refresh. I want to find a way to set a cookie to remember the cart items as well, and I thought setting a cookie for each item/quantity pair was the way to go until I started trying to figure out how to unset all those cookies if the user empties their cart. Is there any way to set cookies with an array for the name? Intead of $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the SESSION? What about storing a unique ID in the cookie, and matching it up with information for that user in a database. It's sort of simulating a sessions, but without the session handler getting involved, which looks slightly messed up from what you've said. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] cookies and carts
On Dec 7, 2009, at 4:39 PM, Allen McCabe wrote: I have a shopping cart type system set up which keeps track of the cart contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is equal to the quantity, so the name/value pair is all the information I need. But sessions are unreliable on the free server I am currently using for this website (not my choice), so I had start using cookies because users were being sporadically logged out, sometimes just on a page refresh. I want to find a way to set a cookie to remember the cart items as well, and I thought setting a cookie for each item/quantity pair was the way to go until I started trying to figure out how to unset all those cookies if the user empties their cart. Is there any way to set cookies with an array for the name? Intead of $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the SESSION? Don't do it this way. At some point (don't know if it's still true), IE had a limit of 20 cookies per domain - this includes cookie arrays. The proper way to do this would be to hold some sort of key in a cookie: user_cart = 'some unique value for this user' Then, in your PHP code, grab the value of $_COOKIE['user_cart'] to reference data in a database. Then, you pull the information from the database with this unique key and use it to display the appropriate items. This is the most secure way to do it (with the proper security measures ;) and it doesn't put 100's of needless cookies on the user's machine. Hope this helps. ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] cookies and carts
On Dec 7, 2009, at 4:40 PM, Ashley Sheridan wrote: On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote: I have a shopping cart type system set up which keeps track of the cart contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is equal to the quantity, so the name/value pair is all the information I need. But sessions are unreliable on the free server I am currently using for this website (not my choice), so I had start using cookies because users were being sporadically logged out, sometimes just on a page refresh. I want to find a way to set a cookie to remember the cart items as well, and I thought setting a cookie for each item/quantity pair was the way to go until I started trying to figure out how to unset all those cookies if the user empties their cart. Is there any way to set cookies with an array for the name? Intead of $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the SESSION? What about storing a unique ID in the cookie, and matching it up with information for that user in a database. It's sort of simulating a sessions, but without the session handler getting involved, which looks slightly messed up from what you've said. Thanks, Ash http://www.ashleysheridan.co.uk Blast your speedier typing!! =P ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] cookies and carts
On Mon, 2009-12-07 at 16:48 -0600, Philip Thompson wrote: On Dec 7, 2009, at 4:40 PM, Ashley Sheridan wrote: On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote: I have a shopping cart type system set up which keeps track of the cart contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is equal to the quantity, so the name/value pair is all the information I need. But sessions are unreliable on the free server I am currently using for this website (not my choice), so I had start using cookies because users were being sporadically logged out, sometimes just on a page refresh. I want to find a way to set a cookie to remember the cart items as well, and I thought setting a cookie for each item/quantity pair was the way to go until I started trying to figure out how to unset all those cookies if the user empties their cart. Is there any way to set cookies with an array for the name? Intead of $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the SESSION? What about storing a unique ID in the cookie, and matching it up with information for that user in a database. It's sort of simulating a sessions, but without the session handler getting involved, which looks slightly messed up from what you've said. Thanks, Ash http://www.ashleysheridan.co.uk Blast your speedier typing!! =P ~Philip By the power of Kenco! Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] cookies and carts
On Dec 7, 2009, at 4:46 PM, Ashley Sheridan wrote: On Mon, 2009-12-07 at 16:48 -0600, Philip Thompson wrote: On Dec 7, 2009, at 4:40 PM, Ashley Sheridan wrote: On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote: I have a shopping cart type system set up which keeps track of the cart contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is equal to the quantity, so the name/value pair is all the information I need. But sessions are unreliable on the free server I am currently using for this website (not my choice), so I had start using cookies because users were being sporadically logged out, sometimes just on a page refresh. I want to find a way to set a cookie to remember the cart items as well, and I thought setting a cookie for each item/quantity pair was the way to go until I started trying to figure out how to unset all those cookies if the user empties their cart. Is there any way to set cookies with an array for the name? Intead of $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the SESSION? What about storing a unique ID in the cookie, and matching it up with information for that user in a database. It's sort of simulating a sessions, but without the session handler getting involved, which looks slightly messed up from what you've said. Thanks, Ash http://www.ashleysheridan.co.uk Blast your speedier typing!! =P ~Philip By the power of Kenco! Thanks, Ash http://www.ashleysheridan.co.uk I hope you don't kiss your mother with that mouth!!
Re: [PHP] cookies and carts
On Mon, 2009-12-07 at 16:53 -0600, Philip Thompson wrote: On Dec 7, 2009, at 4:46 PM, Ashley Sheridan wrote: On Mon, 2009-12-07 at 16:48 -0600, Philip Thompson wrote: On Dec 7, 2009, at 4:40 PM, Ashley Sheridan wrote: On Mon, 2009-12-07 at 14:39 -0800, Allen McCabe wrote: I have a shopping cart type system set up which keeps track of the cart contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is equal to the quantity, so the name/value pair is all the information I need. But sessions are unreliable on the free server I am currently using for this website (not my choice), so I had start using cookies because users were being sporadically logged out, sometimes just on a page refresh. I want to find a way to set a cookie to remember the cart items as well, and I thought setting a cookie for each item/quantity pair was the way to go until I started trying to figure out how to unset all those cookies if the user empties their cart. Is there any way to set cookies with an array for the name? Intead of $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the SESSION? What about storing a unique ID in the cookie, and matching it up with information for that user in a database. It's sort of simulating a sessions, but without the session handler getting involved, which looks slightly messed up from what you've said. Thanks, Ash http://www.ashleysheridan.co.uk Blast your speedier typing!! =P ~Philip By the power of Kenco! Thanks, Ash http://www.ashleysheridan.co.uk I hope you don't kiss your mother with that mouth!! Not a coffee man? :p Thanks, Ash http://www.ashleysheridan.co.uk
[PHP] Passing HTML array index to JS?
Hey all, I have an HTML field like this input type=text name=qty[] value=!!quantity!! size=4 style=text-align: right; onblur=calculateBidUnit(); ... and what I need to do is pass to the calculateBidUnit function the value of quantity, do a calculation on it and plug into this field. input type=text name=bid_unit_value[] value= size=4 Which of course I know how to do for non-array values, but not sure how to get the values to do the calculation on the JS side if the fields are in an array. Any help, as always, is greatly appreciated, Skip -- Skip Evans PenguinSites.com, LLC 503 S Baldwin St, #1 Madison WI 53703 608.250.2720 http://penguinsites.com Those of you who believe in telekinesis, raise my hand. -- Kurt Vonnegut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing HTML array index to JS?
On Dec 7, 2009, at 5:02 PM, Skip Evans wrote: Hey all, I have an HTML field like this input type=text name=qty[] value=!!quantity!! size=4 style=text-align: right; onblur=calculateBidUnit(); ... and what I need to do is pass to the calculateBidUnit function the value of quantity, do a calculation on it and plug into this field. input type=text name=bid_unit_value[] value= size=4 Which of course I know how to do for non-array values, but not sure how to get the values to do the calculation on the JS side if the fields are in an array. Any help, as always, is greatly appreciated, Skip This question is probably more appropriate for a JS list... but I'm not mean, so I'll let you know. The easiest way would be to update the blur event qty input: onblur=calculateBidUnit(this.value); Now you have the value sent to that function. Another way would be to give your input and output an id each - let's say 'qty' and 'bid_unit_value', respectively. Then reference those ids in your function. This gives you the following: input type=text name=qty[] value=!!quantity!! onblur=calculateBidUnit(); id=qty / input type=text name=bid_unit_value[] value= id=bid_unit_value / script type=text/javascript function calculateBidUnit () { var qty = document.getElementById('qty'); var buv = document.getElementById('bid_unit_value'); buv.value = qty.value; } /script I'll give you a small warning. All browsers are not alike, so my recommendation would be to use a library that handles the cross-browser compatibility portion of javascript (I use Mootools). Nonetheless, the above *should* work. Learning the bare bones of javascript will help with the more complicated stuff and you'll be smarter for it! =P Hope that helps, ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing HTML array index to JS?
Hey Philip, But will that ID value identify the right member of each array? I thought about that but just assumed that it would not. Skip Philip Thompson wrote: On Dec 7, 2009, at 5:02 PM, Skip Evans wrote: Hey all, I have an HTML field like this input type=text name=qty[] value=!!quantity!! size=4 style=text-align: right; onblur=calculateBidUnit(); ... and what I need to do is pass to the calculateBidUnit function the value of quantity, do a calculation on it and plug into this field. input type=text name=bid_unit_value[] value= size=4 Which of course I know how to do for non-array values, but not sure how to get the values to do the calculation on the JS side if the fields are in an array. Any help, as always, is greatly appreciated, Skip This question is probably more appropriate for a JS list... but I'm not mean, so I'll let you know. The easiest way would be to update the blur event qty input: onblur=calculateBidUnit(this.value); Now you have the value sent to that function. Another way would be to give your input and output an id each - let's say 'qty' and 'bid_unit_value', respectively. Then reference those ids in your function. This gives you the following: input type=text name=qty[] value=!!quantity!! onblur=calculateBidUnit(); id=qty / input type=text name=bid_unit_value[] value= id=bid_unit_value / script type=text/javascript function calculateBidUnit () { var qty = document.getElementById('qty'); var buv = document.getElementById('bid_unit_value'); buv.value = qty.value; } /script I'll give you a small warning. All browsers are not alike, so my recommendation would be to use a library that handles the cross-browser compatibility portion of javascript (I use Mootools). Nonetheless, the above *should* work. Learning the bare bones of javascript will help with the more complicated stuff and you'll be smarter for it! =P Hope that helps, ~Philip -- Skip Evans PenguinSites.com, LLC 503 S Baldwin St, #1 Madison WI 53703 608.250.2720 http://penguinsites.com Those of you who believe in telekinesis, raise my hand. -- Kurt Vonnegut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Live PHP Code Templates for NetBeans - accelerate your php development.
You can import the templates by going to Tools Options Code Templates then click on the Import button at the bottom of the window. To use the templates: 1. Create or open an HTML page 2. Enter the name name of the template then press the Tab key on the keyboard. Best regards, __ Raymond Irving Raxan for PHP - Building Rich Applications one Page at a Time From: German Geek geek...@gmail.com To: Raymond Irving xwis...@yahoo.com Cc: PHP-General List php-general@lists.php.net Sent: Mon, December 7, 2009 5:16:04 PM Subject: Re: [PHP] Live PHP Code Templates for NetBeans - accelerate your php development. Hi, I would like to check this out. How do you enable these code templates in NetBeans? 2009/12/8 Raymond Irving xwis...@yahoo.com Hello Everyone, I've made a few code templates (HTML, PHP) available for everyone to download and use with NetBeans 6.7 or higher. It will greatly accelerate your php development. http://code.google.com/p/raxan/downloads/detail?name=code-templates.zipcan=2q= And if your interested in further accelerating your PHP/Ajax development, then you might want to check out the new and improved Raxan for PHP (http://raxanpdi.com/) __ Raymond Irving Raxan for PHP - Ajax just got a whole lot easier!
Re: [PHP] Passing HTML array index to JS?
On Dec 7, 2009, at 6:32 PM, Skip Evans wrote: Hey Philip, But will that ID value identify the right member of each array? I thought about that but just assumed that it would not. Skip Philip Thompson wrote: On Dec 7, 2009, at 5:02 PM, Skip Evans wrote: Hey all, I have an HTML field like this input type=text name=qty[] value=!!quantity!! size=4 style=text-align: right; onblur=calculateBidUnit(); ... and what I need to do is pass to the calculateBidUnit function the value of quantity, do a calculation on it and plug into this field. input type=text name=bid_unit_value[] value= size=4 Which of course I know how to do for non-array values, but not sure how to get the values to do the calculation on the JS side if the fields are in an array. Any help, as always, is greatly appreciated, Skip This question is probably more appropriate for a JS list... but I'm not mean, so I'll let you know. The easiest way would be to update the blur event qty input: onblur=calculateBidUnit(this.value); Now you have the value sent to that function. Another way would be to give your input and output an id each - let's say 'qty' and 'bid_unit_value', respectively. Then reference those ids in your function. This gives you the following: input type=text name=qty[] value=!!quantity!! onblur=calculateBidUnit(); id=qty / input type=text name=bid_unit_value[] value= id=bid_unit_value / script type=text/javascript function calculateBidUnit () { var qty = document.getElementById('qty'); var buv = document.getElementById('bid_unit_value'); buv.value = qty.value; } /script I'll give you a small warning. All browsers are not alike, so my recommendation would be to use a library that handles the cross-browser compatibility portion of javascript (I use Mootools). Nonetheless, the above *should* work. Learning the bare bones of javascript will help with the more complicated stuff and you'll be smarter for it! =P Hope that helps, ~Philip Each text input will only contain 1 value... and contain 1 unique id. So, if you have multiple input boxes with the same name (qty[]), only the $_POST output will contain an array of each value. See below... input type=text name=qty[] value=1 id=qty1 onblur=calc(this.value); / input type=text name=qty[] value=2 id=qty2 onblur=calc(this.value); / input type=text name=qty[] value=3 id=qty3 onblur=calc(this.value); / input type=text name=bid_unit_value[] value= id=buv / script type=text/javascript function calc (value) { document.getElementById('buv').value = value; } /script When you blur qty1, buv will receive the value 1; blur qty2, buv will be 2; and so on. The last input box that you blur on will determine buv's final value (unless you throw in some logic to handle this)... script type=text/javascript function calc (value) { var buv = document.getElementById('buv'); if (buv.value == '') buv.value = value; } /script So, let's say you blur on qty2 and then submit the form, your PHP script will have this in $_POST... Array ( [qty] = Array ( [0] = 1 [1] = 2 [3] = 3 ) [bid_unit_value] = Array ( [0] = 2 ) ) If this is not what you're wanting, you will need to modify the behavior above. If you're wanting the bid_unit_value to contain all the values of each blur, you may want to do something like this... script type=text/javascript function calc (value) { var buv = document.getElementById('buv'); if (buv.value == '') buv.value = value; else buv.value += '|'+value; } /script Which may result from each blur in $_POST to be... Array ( [qty] = Array ( [0] = 1 [1] = 2 [3] = 3 ) [bid_unit_value] = Array ( [0] = 2|1|3 ) ) Or something along those lines. Then you can just explode() on that first index to get individual values. Maybe you can clarify your ultimate goal and we can assist you in what the best plan is. Hope that helps, ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] cookies and carts
On Mon, Dec 07, 2009 at 02:39:28PM -0800, Allen McCabe wrote: I have a shopping cart type system set up which keeps track of the cart contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is equal to the quantity, so the name/value pair is all the information I need. But sessions are unreliable on the free server I am currently using for this website (not my choice), so I had start using cookies because users were being sporadically logged out, sometimes just on a page refresh. I want to find a way to set a cookie to remember the cart items as well, and I thought setting a cookie for each item/quantity pair was the way to go until I started trying to figure out how to unset all those cookies if the user empties their cart. Is there any way to set cookies with an array for the name? Intead of $_COOKIE['item_number'] have $_COOKIE['cart']['item_number'] like I have the SESSION? First, don't use multiple cookies; already covered elsewhere. Second, you can serialize/unserialize array data and store it compactly in a cookie. See the serialize() and unserialize() functions on php.net. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php