You are here: Re: Getting quantity input for each product in a product/price associative array « PHP Language « IT news, forums, messages
Re: Getting quantity input for each product in a product/price associative array

Posted by Ric on 01/03/07 12:14

Ryan schrieb:
> The only problem with that, is I'm trying to stay within the guidelines
> of where I am in the book. It appears I'm having trouble just sending
> data in an array from one site to another. I take it using the html
> 'sumbit' won't work in a php script? I tried using regular arrays to

Sure it does, but the problem with submitting and storing data with that
is, that you have to remember every input that was done in each html
page e.g.:


page1(var1,var2) ->page2([var1,var2],var3)->page3([var1,var2,var3],var4)

This is not very convienient, page1, would submit var1 and var2, the php
script that gets these vars would then add them as hidden fields to
page2, this way they would be send along to page3, you see lots of work.


Therefore if have lots of data to store you do that for example in a
SESSION , you start a new session, then as log as this session is valid
you can store data on the server for this specific user, each page then
can access this SESSION data without the need of transfering if from one
page to the ther vuia form submits.


> store price, names, and the quantity the user inputs, but when I try to
> echo any of that into the process.php script, nothing displays. It's
> not a huge ordeal, I just though I'd try update my pages as I go along
> with the book. Thanks though!
>
> Jussist wrote:
>> Now this is a perfect place to go OO. Instead of having those weird
>> associative arrays, use objects.
>>
>> <?php
>> class Prodcuct {
>> $name;
>> $price;
>> }
>> ?>
>> <?php
>> class CartItem {
>> $product;
>> $quantity;
>> }
>> ?>
>> <?php
>> $newProductToCart = new CartItem();
>> $newProductToCart->setProduct($myProduct);
>> $newProductToCart->setAmount(5);
>> $MyCart[] = $newProductToCart;
>> ?>
>> <?php
>> for($i=0;$i<count($MyCart);$i++) {
>> echo "Product:" . $MyCart[$i]->getProduct()->getName() . " - " .
>> $MyCart[$i]->getAmount();
>> }
>> ?>
>>
>> That's the general idea anyway.
>>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация