from ASP to PHP
-
hi i am developping and e-trade website with PHP and i was programming with ASP before. i find a problem i don't find in PHP what can replace the dictionary object. can u help me.
I haven't used asp in ages (don't think I ever used a Dictionary object), but assuming the Dictionary object is a key/value type deal, you can simply use a standard php array...
$myarray = array('cat' => 'A cat says meow', 'dog' => 'A dog says woof');
or$myarray = array(); $myarray['cat'] = 'A cat says meow'; $myarray['dog'] = 'A dog says woof';
You can access an individual key/value pair like:$key = 'cat'; // if key is set, output its value if (isset($myarray[$key])) echo $myarray[$key];
and you can iterate through all items like this...// retrieve all key/value pairs in array $key = ""; $value = ""; while (list($key, $value) = each($myarray)) echo $key . ' => ' . $value;
There should be lots of other examples in the array section of the php help file. -
I haven't used asp in ages (don't think I ever used a Dictionary object), but assuming the Dictionary object is a key/value type deal, you can simply use a standard php array...
$myarray = array('cat' => 'A cat says meow', 'dog' => 'A dog says woof');
or$myarray = array(); $myarray['cat'] = 'A cat says meow'; $myarray['dog'] = 'A dog says woof';
You can access an individual key/value pair like:$key = 'cat'; // if key is set, output its value if (isset($myarray[$key])) echo $myarray[$key];
and you can iterate through all items like this...// retrieve all key/value pairs in array $key = ""; $value = ""; while (list($key, $value) = each($myarray)) echo $key . ' => ' . $value;
There should be lots of other examples in the array section of the php help file.the good in the Dictionary object is that can open a session in the client part(the pc of the client) and you can store the information. in the case that he refresh the page all the information still in his pc ,and that what i am looking for ,and i don't know if i can do that with PHP.
-
the good in the Dictionary object is that can open a session in the client part(the pc of the client) and you can store the information. in the case that he refresh the page all the information still in his pc ,and that what i am looking for ,and i don't know if i can do that with PHP.
Session management is available in PHP. The default setup will store the session data in a temporary folder on the server. You can add your own custom handlers to provide your own storage method if need be. (I save session data to an mysql table) You need to call session_start() on each page you'll be manipulating session data. You can access the session data via the $_SESSION superglobal: page1.php
<?php // always call session_start 1st session_start(); $_SESSION['session_data_item_1'] = 'one'; $_SESSION['session_data_item_2'] = 'two'; ?> <a href="page2.php">Goto Page 2</a>
page2.php<?php // always call session_start 1st session_start(); echo $_SESSION['session_data_item_1']; echo $_SESSION['session_data_item_2']; ?>
php session tutorials: http://www.phpfreaks.com/tutorials/41/0.php http://www.free2code.net/plugins/articles/read.php?id=184 Lookup the session_ functions in php help file for more examples.Pssst. You see that little light on your monitor? That's actually a spy camera, and I'm tracking your every move...
-
Session management is available in PHP. The default setup will store the session data in a temporary folder on the server. You can add your own custom handlers to provide your own storage method if need be. (I save session data to an mysql table) You need to call session_start() on each page you'll be manipulating session data. You can access the session data via the $_SESSION superglobal: page1.php
<?php // always call session_start 1st session_start(); $_SESSION['session_data_item_1'] = 'one'; $_SESSION['session_data_item_2'] = 'two'; ?> <a href="page2.php">Goto Page 2</a>
page2.php<?php // always call session_start 1st session_start(); echo $_SESSION['session_data_item_1']; echo $_SESSION['session_data_item_2']; ?>
php session tutorials: http://www.phpfreaks.com/tutorials/41/0.php http://www.free2code.net/plugins/articles/read.php?id=184 Lookup the session_ functions in php help file for more examples.Pssst. You see that little light on your monitor? That's actually a spy camera, and I'm tracking your every move...
i am making a e-trade website and i have for exemple 03 products 1) Product N°1 = 5$ 2) Product N°1 = 10$ 1) Product N°1 = 8$ and when the consumer choise one product one row of matrix will be created in an other page with the name of the product and the price ---------------- product1 / 5$ ---------------- and like that with the second product and the third . and i want to store this session in the PC of the client ,cause the client can delete a product after he choise it.
-
i am making a e-trade website and i have for exemple 03 products 1) Product N°1 = 5$ 2) Product N°1 = 10$ 1) Product N°1 = 8$ and when the consumer choise one product one row of matrix will be created in an other page with the name of the product and the price ---------------- product1 / 5$ ---------------- and like that with the second product and the third . and i want to store this session in the PC of the client ,cause the client can delete a product after he choise it.
You can add/update/delete any type of variable at anytime when you use php sessions. Here's a general take at what I'd do for an e-cart app. Firstly, I'd place all e-cart code in a separate file, that way you can include it in any file you want. (even better, you can make a class for it) include_ecart.php: (not checked for errors)
<?php /* e-cart related functions */ function does_ecart_exist() { // if 'ecart' session variable is set, it exists return (isset($_SESSION['ecart'])); } function is_item_in_ecart($product_id) { // make sure the e-cart exists! if (!does_ecart_exist()) return (false); return (isset($_SESSION['ecart'][$product_id])); } function add_item_to_ecart($product_id, $product_name, $unit_price, $quantity) { // make sure the e-cart exists! if (!does_ecart_exist()) return (false); // todo: determine what to do if item already in cart... // if (is_item_in_ecart($product_id)) // update or return error? // create an array to hold the product data $product_data = array('name' => $product_name, 'price' => $unit_price, 'quantity' => $quantity); // add the product to the e-cart array, using it's id as the key $_SESSION['ecart'][$product_id] = $product_data; return (true); } function view_ecart_contents() { // make sure the e-cart exists! if (!does_ecart_exist()) return (false); // grab each item in the cart, and print out data $product_id = 0; $product_data = array(); while (list($product_id, $product_data) = each($_SESSION['ecart'])) { printf('Product Id: %1$s, Name: %2$s, Price: %3$s, Quantity: %4$s', $product_id, &n