Re: [PHP] Array / form processing

2010-10-08 Thread Sebastian Detert

Ron Piggott schrieb:

I am writing a custom shopping cart that eventually the cart will be
uploaded to PayPal for payment.  I need to be able to include the option
that the purchase is a gift certificate.



At present my add to cart function goes like this:

===
# Gift Certificate: 1 is a gift; 2 is personal use

if ( $gift_certificate == yes ) {
$gift = 1;
} else {
$gift = 2;
}

$_SESSION['life_coaching_order'][$product][$gift]['quantity'] = 
$_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1;

===

Now I need to display the shopping cart contents.  I want to do this
through an array as the contents of the shopping cart are in a session
variable.  I start displaying the shopping cart contents by a FOREACH
loop:

===
foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference
= $value ) {
===

What I need help with is that I don't know how to test the value of $gift
in the above array if it is a 1 or 2 (which symbolizes this is a gift
certificate).

I have something like this in mind:
if ( $_SESSION['life_coaching_order'] == 2 ) {

But I don't know how to access all the components of the array while I am
going through the FOREACH loop.

By using a 1 or 2 I have made gift certificates their own product.  If
you a better method I could use please provide me with this feedback.

Ron

The Verse of the Day
Encouragement from God's Word
www.TheVerseOfTheDay.info


  
First at all, I wouldn't use 1 or 2 for defining important informations. 
use something like

define('ORDER_GIFT', 1);
define('ORDER_PERSONAL',2);

If you want to check all values of your array you can use several 
foreach loops like


foreach ($_SESSION['life_coaching_order'] AS $coaching_product = $tmp_array)
{
 foreach ($tmp_array as $coaching_gift = $tmp_array2)
 {
   switch ($coaching_gift)
 case ORDER_GIFT: break;

 case ORDER_PERSONAL: break;
)
 } 
}



Personally I would prefer writing a class like

class Order
{
  private $product;
  private $gift;
  private $quantity;

  const ORDER_GIFT=1;
  const ORDER_PERSONAL=2;

 function getGift() {
   return $this - gift;
 }
}

using

$_SESSION['life_coaching_order'][] = new Order();

foreach ( $_SESSION['life_coaching_order'] as $order )
{
 switch ( $order - getGift() )

 case ORDER_GIFT: break;

 case ORDER_PERSONAL: break;
  
} 


I hope that will help you,

Sebastian
http://elygor.de


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



[PHP] Array / form processing

2010-10-07 Thread Ron Piggott

I am writing a custom shopping cart that eventually the cart will be
uploaded to PayPal for payment.  I need to be able to include the option
that the purchase is a gift certificate.



At present my add to cart function goes like this:

===
# Gift Certificate: 1 is a gift; 2 is personal use

if ( $gift_certificate == yes ) {
$gift = 1;
} else {
$gift = 2;
}

$_SESSION['life_coaching_order'][$product][$gift]['quantity'] = 
$_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1;
===

Now I need to display the shopping cart contents.  I want to do this
through an array as the contents of the shopping cart are in a session
variable.  I start displaying the shopping cart contents by a FOREACH
loop:

===
foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference
= $value ) {
===

What I need help with is that I don't know how to test the value of $gift
in the above array if it is a 1 or 2 (which symbolizes this is a gift
certificate).

I have something like this in mind:
if ( $_SESSION['life_coaching_order'] == 2 ) {

But I don't know how to access all the components of the array while I am
going through the FOREACH loop.

By using a 1 or 2 I have made gift certificates their own product.  If
you a better method I could use please provide me with this feedback.

Ron

The Verse of the Day
Encouragement from God's Word
www.TheVerseOfTheDay.info


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



Re: [PHP] Array / form processing

2010-10-07 Thread chris h
$_SESSION['life_coaching_order'][$product][$gift]['quantity'] =
$_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1;
===

...

===
foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference
= $value ) {
===


In this example $value would be an array. To test if it is a gift or not you
would do this from within the foreach loop:

//gift
if ( isset($value[1])  isset($value[1]['quantity']) )
{
  $gift_quantity = $value[1]['quantity'];
}

//personal use
if ( isset($value[2])  isset($value[2]['quantity']) )
{
  $personal_quantity = $value[2]['quantity'];
}


Technically the above IF's are optional, but they are proper syntax.

I don't know how you are with OOP, but you may have more luck using objects
instead of a complex array.

Chris H.


On Thu, Oct 7, 2010 at 3:35 PM, Ron Piggott
ron.pigg...@actsministries.orgwrote:


 I am writing a custom shopping cart that eventually the cart will be
 uploaded to PayPal for payment.  I need to be able to include the option
 that the purchase is a gift certificate.



 At present my add to cart function goes like this:

 ===
 # Gift Certificate: 1 is a gift; 2 is personal use

 if ( $gift_certificate == yes ) {
$gift = 1;
 } else {
$gift = 2;
 }

 $_SESSION['life_coaching_order'][$product][$gift]['quantity'] =
 $_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1;
 ===

 Now I need to display the shopping cart contents.  I want to do this
 through an array as the contents of the shopping cart are in a session
 variable.  I start displaying the shopping cart contents by a FOREACH
 loop:

 ===
 foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference
 = $value ) {
 ===

 What I need help with is that I don't know how to test the value of $gift
 in the above array if it is a 1 or 2 (which symbolizes this is a gift
 certificate).

 I have something like this in mind:
 if ( $_SESSION['life_coaching_order'] == 2 ) {

 But I don't know how to access all the components of the array while I am
 going through the FOREACH loop.

 By using a 1 or 2 I have made gift certificates their own product.  If
 you a better method I could use please provide me with this feedback.

 Ron

 The Verse of the Day
 Encouragement from God's Word
 www.TheVerseOfTheDay.info


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




Re: [PHP] Array / form processing

2010-10-07 Thread Ron Piggott

Many thanks, Chris.

I have one additional question about this shopping cart project.  I need
to make a submit button for the purpose of removing an item from the
shopping cart.

input type=submit name=submit value=Remove class=place_order/

What I am struggling with is to find an effective method for passing the
product serial number (auto_increment in the table it is stored in) so I
know which product the user is removing from their purchase.  Then I will
just unset the session variable that matches.

What are your suggestion(s)?

Thank you your help with my original question Chris.

Ron

 $_SESSION['life_coaching_order'][$product][$gift]['quantity'] =
 $_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1;
 ===

 ...

 ===
 foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference
 = $value ) {
 ===


 In this example $value would be an array. To test if it is a gift or not
 you
 would do this from within the foreach loop:

 //gift
 if ( isset($value[1])  isset($value[1]['quantity']) )
 {
   $gift_quantity = $value[1]['quantity'];
 }

 //personal use
 if ( isset($value[2])  isset($value[2]['quantity']) )
 {
   $personal_quantity = $value[2]['quantity'];
 }


 Technically the above IF's are optional, but they are proper syntax.

 I don't know how you are with OOP, but you may have more luck using
 objects
 instead of a complex array.

 Chris H.


 On Thu, Oct 7, 2010 at 3:35 PM, Ron Piggott
 ron.pigg...@actsministries.orgwrote:


 I am writing a custom shopping cart that eventually the cart will be
 uploaded to PayPal for payment.  I need to be able to include the option
 that the purchase is a gift certificate.



 At present my add to cart function goes like this:

 ===
 # Gift Certificate: 1 is a gift; 2 is personal use

 if ( $gift_certificate == yes ) {
$gift = 1;
 } else {
$gift = 2;
 }

 $_SESSION['life_coaching_order'][$product][$gift]['quantity'] =
 $_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1;
 ===

 Now I need to display the shopping cart contents.  I want to do this
 through an array as the contents of the shopping cart are in a session
 variable.  I start displaying the shopping cart contents by a FOREACH
 loop:

 ===
 foreach ($_SESSION['life_coaching_order'] AS
 $coaching_fee_theme_reference
 = $value ) {
 ===

 What I need help with is that I don't know how to test the value of
 $gift
 in the above array if it is a 1 or 2 (which symbolizes this is a gift
 certificate).

 I have something like this in mind:
 if ( $_SESSION['life_coaching_order'] == 2 ) {

 But I don't know how to access all the components of the array while I
 am
 going through the FOREACH loop.

 By using a 1 or 2 I have made gift certificates their own product.
 If
 you a better method I could use please provide me with this feedback.

 Ron

 The Verse of the Day
 Encouragement from God's Word
 www.TheVerseOfTheDay.info


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






The Verse of the Day
Encouragement from God's Word
www.TheVerseOfTheDay.info


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



Re: [PHP] Array / form processing

2010-10-07 Thread chris h
input type=submit name=submit value=Remove class=place_order/

I don't know what the context is like, but you may be better off just using
an entire form here with hidden fields. i.e.

form target=... action=...
 input type=hidden name=submit value=Remove /
 input type=hidden name=product_so value=1234 /
 input type=submit value=Remove class=place_order/
/form


Without knowing what else is going on in your page, and how the request is
being handled on the server, it's kind of hard to give exact advice. :)

Chris H.


RE: [PHP] Array form processing

2010-06-30 Thread Ford, Mike
 -Original Message-
 From: Ron Piggott [mailto:ron.pigg...@actsministries.org]
 Sent: 29 June 2010 22:22
 
 Am I on the right track?  I don't know what to do with the second
 FOREACH

Sort of.

 
 ?php
 
 foreach($_REQUEST as $key = $val) {
  $$key = $val;
echo $key . :  . $val . br;
 
if ( $val == Array ) {

I would prefer to use is_array() here:

if (is_array($val))

   $i=0;
 

At this point, you've just proved that $val is an array (whichever test you 
use!), so simply foreach it like one. I know you know how to do that as you did 
it with $_REQUEST above!

   foreach ($val) {
   echo $val[$i]br;
   $i++;
   }

foreach ($val as $option) {
   echo $optionbr /\n;
}

 
}
 }
 
 ?

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] Array form processing

2010-06-30 Thread tedd

At 4:54 PM -0400 6/29/10, Ron Piggott wrote:

I am trying to process a form where the user uses checkboxes:

input type=checkbox name=painDesc[] value=1 /Sharp
input type=checkbox name=painDesc[] value=2 /Stabbing
input type=checkbox name=painDesc[] value=3 /Jabbing

When I do:

foreach($_REQUEST as $key = $val) {
 $$key = $val;
 echo $key . :  . $val . br;
}

The output is:

painDesc: Array

I need to know the values of the array (IE to know what the user is
checking), not that there is an array.  I hope to save these values to the
database.

Thank you.

Ron


Ron:

Try this:

http://php1.net/b/form-checkbox/

If you want the form to retain the values, try this:

http://php1.net/b/form-checkbox1/


Cheers,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



[PHP] Array form processing

2010-06-29 Thread Ron Piggott

I am trying to process a form where the user uses checkboxes:

input type=checkbox name=painDesc[] value=1 /Sharp
input type=checkbox name=painDesc[] value=2 /Stabbing
input type=checkbox name=painDesc[] value=3 /Jabbing

When I do:

foreach($_REQUEST as $key = $val) {
 $$key = $val;
 echo $key . :  . $val . br;
}

The output is:

painDesc: Array

I need to know the values of the array (IE to know what the user is
checking), not that there is an array.  I hope to save these values to the
database.

Thank you.

Ron


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



Re: [PHP] Array form processing

2010-06-29 Thread Ashley Sheridan
On Tue, 2010-06-29 at 16:54 -0400, Ron Piggott wrote:

 I am trying to process a form where the user uses checkboxes:
 
 input type=checkbox name=painDesc[] value=1 /Sharp
 input type=checkbox name=painDesc[] value=2 /Stabbing
 input type=checkbox name=painDesc[] value=3 /Jabbing
 
 When I do:
 
 foreach($_REQUEST as $key = $val) {
  $$key = $val;
echo $key . :  . $val . br;
 }
 
 The output is:
 
 painDesc: Array
 
 I need to know the values of the array (IE to know what the user is
 checking), not that there is an array.  I hope to save these values to the
 database.
 
 Thank you.
 
 Ron
 
 


You need to iterate that array, as that holds the values of everything
sent by the browser

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Array form processing

2010-06-29 Thread Shreyas Agasthya
The painDesc array is what that should be iterated.

--Shreyas

On Wed, Jun 30, 2010 at 2:27 AM, Ashley Sheridan
a...@ashleysheridan.co.ukwrote:

 On Tue, 2010-06-29 at 16:54 -0400, Ron Piggott wrote:

  I am trying to process a form where the user uses checkboxes:
 
  input type=checkbox name=painDesc[] value=1 /Sharp
  input type=checkbox name=painDesc[] value=2 /Stabbing
  input type=checkbox name=painDesc[] value=3 /Jabbing
 
  When I do:
 
  foreach($_REQUEST as $key = $val) {
   $$key = $val;
 echo $key . :  . $val . br;
  }
 
  The output is:
 
  painDesc: Array
 
  I need to know the values of the array (IE to know what the user is
  checking), not that there is an array.  I hope to save these values to
 the
  database.
 
  Thank you.
 
  Ron
 
 


 You need to iterate that array, as that holds the values of everything
 sent by the browser

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk





-- 
Regards,
Shreyas Agasthya


Re: [PHP] Array form processing

2010-06-29 Thread Ron Piggott
Am I on the right track?  I don't know what to do with the second FOREACH

?php

foreach($_REQUEST as $key = $val) {
 $$key = $val;
 echo $key . :  . $val . br;

 if ( $val == Array ) {
$i=0;

foreach ($val) {
echo $val[$i]br;
$i++;
}

 }
}

?


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



Re: [PHP] Array form processing

2010-06-29 Thread Jim Lucas
Ron Piggott wrote:
 I am trying to process a form where the user uses checkboxes:
 
 input type=checkbox name=painDesc[] value=1 /Sharp
 input type=checkbox name=painDesc[] value=2 /Stabbing
 input type=checkbox name=painDesc[] value=3 /Jabbing
 
 When I do:
 
 foreach($_REQUEST as $key = $val) {
  $$key = $val;
echo $key . :  . $val . br;
 }
 
 The output is:
 
 painDesc: Array
 
 I need to know the values of the array (IE to know what the user is
 checking), not that there is an array.  I hope to save these values to the
 database.
 
 Thank you.
 
 Ron
 
 

Think about it...

You would not ?php echo $_REQUEST; ? and expect to get the value of any form
field would you.  No, you wouldn't.

Given the following form...

form
Titleinput type=text name=title value= /br /
Subjectinput type=text name=subject value= /br /
input type=submit name=submit value=Send it! /
/form

on the processing page, I would access those variables by writing the following.

echo $_REQUEST['title'];
echo $_REQUEST['subject'];

With that said, going back to your issue, you would do this:

if ( $_REQUEST['painDesc']  count($_REQUEST['painDesc']) ) {
  foreach($_REQUEST['painDesc'] as $key = $val) {
echo {$key}:{$val}br /;
  }
}

-- 
Jim Lucas

A: Maybe because some people are too annoyed by top-posting.
Q: Why do I not get an answer to my question(s)?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

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