Page 1 of 1
Imbedding? PhP into a clickable area or buttons function
Posted: Thu Jun 12, 2003 8:34 am
by steedvlx
I had so much luck before, I thought I'd press my luck and ask another newbie question. I'm starting to see how dangerous it is to write your own storefront stuff when you are just learning
I am trying to make clickable buttons run scripts specific to ADD, DELETE, and UPDATE for a specific record within a record detail region.
The specific thing is to allow people to perform these functions on their shopping cart or wishlist or user data when it is displayed. I understand HOW to write the basic code to perform these three functions, but I don't know how to get the button to execute it for the exact data row on which the button is displayed.
Take a look at
http://www.sgthost.com/japanese/j_cart/j_cart_main.php
and you'll probably know more about what I'm trying to do than I do.
This forum has already supplied answers to 4 questions today, and I only had to ask one.

(until this one that is)
SteedVLX
Posted: Thu Jun 12, 2003 8:40 am
by B|uSmurf
Ever take a look into using cookies or sessions for it?
Posted: Thu Jun 12, 2003 9:12 am
by volka
each row needs an unique identifier. I'm not quite sure how the structure of your table look like, but let's assume you're using the session- and productId as unique key.
Now you have to ship all necessary parameters in your link/button.
The sessionId you can get with
session_id() (after starting the session), so you do not need to transfer it, but the product id, e.g.
<a href="myCart.php?add=345">
Same for delete
<a href="myCart.php?delete=345"> and modifiy
<a href="myCart.php?increment=345"> or
<a href="myCart.php?decrement=345">
edit: Now you have to decide wether to store this information as session data or/and persitent in a database.
Until the customer actually performs the purchase order sessions will suffice, so the action for the add-link looks like
Code: Select all
if ( isset($_SESSION['cart'][$_GET['add']]) )
++$_SESSION['cart'][$_GET['add']];
else
$_SESSION['cart'][$_GET['add']] = 1;
// same as ?increment=345
Posted: Thu Jun 12, 2003 9:13 am
by steedvlx
sounds interesting. I'm still just a newbie. But, the way I have the data structured, I don't use session numbers to keep up with the items in a particular cart. So, a session_array wouldn't do me any good.
I encourage them to log out and will automatically log them out and destroy session data after 8 hours anyway. instead, I want to keep cart items by their user_index_number. (people in Japan will not stay logged in anyway) Then I can run a routine once a month to clear out items more than 30 days old without affecting their wishlists.
If I'm missing something though...it won't be the first time.
--------------------
SteedVLX
Posted: Thu Jun 12, 2003 9:19 am
by volka
do they have to login (and therefor can be identified) before using the cart?
Posted: Thu Jun 12, 2003 9:50 am
by steedvlx
Yes sir...
The entire cart functions on the $session_usernumber which is set as a session variable after a sucessfull log in and cart:user_number ensures that their cart data is preserved (even if they log out and until I delete it through manual admin)
If they don't log out, it is stored in the session data for eight hours.
If they add something to the cart, it is intended to be stored under cart;user_number.
The cart table structure is simple:
cart_id_number (Index, unique, auto)
user_number (Index)
wishlist_indicator (0 or 1) So they can "move to wishlist and still use the same table"
cart_prod_id_index (corresponds to prod_index in the products table)
cart_prod_part_number (corresponds to prod_number in products table)
cart_quantity
cart_sell_price
cart_line_total
last_access (timestamp)
The session variable that I thought would make all of this possible is $session_usernumber.
Thanks for the information when using sessions, I'm saving that for my next attempt.
If any ideas or resources come to mind, please LMK.
Thanks
---------------------
SteedVLX
Posted: Sat Jun 14, 2003 6:53 am
by steedvlx
I'm not sure if this works here. But, I am still struggling with this issue and would like to BTT (bump To the Top) if possible.
Anyway, I have buttons set in a repeating-row region. The table above is the datasource. I'm not asking for ready-made code or anything, but a definite direction that a PhP newbie like me can handle. Sessions won't cut it. I'm afraid that ship has sailed by me deciding to go database-driven. (My bad? or not?)
As always Thank You
--------------------
SteedVLX