DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Associative arrays to update Cart Cookie .... image filename

By: | 24 Jul 2009 11:50 am


Hi

Thanks for the advice.

One other problem is that there should be an image of the item at the start of the line.

Images are stored in the usual "images/" folder.
The file has the $item as it`s name.
ie : filename = `images/` . $item . `.jpg`
but the image does not display.

server is localhost , ( Apache,Wamp )
How do I construct the correct filename ?


Could anyone help out by giving an example of how the data from this array can be displayed on a page (html table) ?

Array ( [ECAcart] => Array (
[coppercasserole] => Array ( [qty] => 1 [desc] => Copper Casserole [price]
=> 2199 )
[steelcasserole] => Array ( [qty] => 1 [desc] => Steel Casserole [price] =>

2099 )
[steelfrying] => Array ( [qty] => 1 [desc] => Steel Frying [price] => 899 )

 )
  )


cheers

You didn`t say what variable all of this is stored in so I`ll call it $array.

print "<table border=`1`>";
foreach ($array[`ECAcart`] as $item)
{
printf("<tr><td>%s</td><td>%s<td><td>%s</td></tr>",
$item[`qty`], $item[`desc`], $item[`price`]
);
}
print "</table>";

Shopping carts are not stored in cookies for good reasons. A cookie is on the client machine and can be manipulated by the person who runs the browser. Hence your "prices" can be changed by them--very bad.

Instead, the session variables would be used to store all of your cart data.It is easy to put an array in the $_SESSION superglobal. The only thing that is stored in a cookie is the session_id which refers to the session variable on the server.

If you are serious about deploying this, I urge you to rethink your cart data storage strategy.

Comments

No Comments Posted for this Article.

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move