Saving an array to a mySQL table
am 14.05.2008 05:11:40 von Ron Piggott
I am writing a shopping cart. I am now ready to take the order from
being in a session variable
$_SESSION['product_selected'][$product_reference_number] to store it
into the orders table.
While the products selected are being displayed in a loop I have the
piece of code
$final_order .= $_SESSION['selection'][$product_reference]
Of course this is only capturing the quantity of $product_reference, not
assigning the array to $final_order and the quantity being ordered.
I am trying to maintain inventory control in my shopping cart and want
to be able to query the orders table to find out what products have left
so I don't sell something I don't have.
Ron
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Saving an array to a mySQL table
am 14.05.2008 05:59:45 von Ron Piggott
If I wasn't clear I am trying to figure out how to save an array in a
mySQL table, both the array and it's value ... in this instance the
product reference and the quantity the customer has decided on. Ron
On Tue, 2008-05-13 at 23:11 -0400, Ron Piggott wrote:
> I am writing a shopping cart. I am now ready to take the order from
> being in a session variable
> $_SESSION['product_selected'][$product_reference_number] to store it
> into the orders table.
>
> While the products selected are being displayed in a loop I have the
> piece of code
>
> $final_order .= $_SESSION['selection'][$product_reference]
>
> Of course this is only capturing the quantity of $product_reference, not
> assigning the array to $final_order and the quantity being ordered.
>
> I am trying to maintain inventory control in my shopping cart and want
> to be able to query the orders table to find out what products have left
> so I don't sell something I don't have.
>
> Ron
>
--
ron.piggott@actsministries.org
www.actsministrieschristianevangelism.org
Acts Ministries Christian Evangelism
"Where People Matter"
12 Burton Street
Belleville, Ontario, Canada K8P 1E6
In Belleville Phone : (613) 967-0032
In North America Call Toll Free : (866) ACTS-MIN
Fax: (613) 967-9963
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Saving an array to a mySQL table
am 14.05.2008 06:14:51 von dmagick
Ron Piggott wrote:
> I am writing a shopping cart. I am now ready to take the order from
> being in a session variable
> $_SESSION['product_selected'][$product_reference_number] to store it
> into the orders table.
>
> While the products selected are being displayed in a loop I have the
> piece of code
>
> $final_order .= $_SESSION['selection'][$product_reference]
>
> Of course this is only capturing the quantity of $product_reference, not
> assigning the array to $final_order and the quantity being ordered.
>
> I am trying to maintain inventory control in my shopping cart and want
> to be able to query the orders table to find out what products have left
> so I don't sell something I don't have.
A couple of ways:
- serialize it first (see php.net/serialize). Doing this means searching
in that table is horrible. This may or may not be a concern but it's
something to be aware of.
- save the details in a new table:
foreach ($array as $k => $v) {
$query = "insert into new_table(cart_id, product_id, product_qty)
values (....)";
}
which makes searching easier (eg you could check that nobody is trying
to buy a product before making it "inactive" or "not for sale").
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php