Page 1 of 2
what to do - an array or ?
Posted: Mon Sep 24, 2007 12:24 pm
by jramaro
Hi
Im echoing out the variables / product info for a user shopping cart.
I store them in a temp database until they get to the order page, and then a SQL query pulls them back out
converts them to $_SESSION variables.
It all works good, but now i have to put this all into a custom mail form (invoice/ receipt) type of format.
I know how to make mail forms and all that. BUT , how will i echo this out to the mail form since its multiple data?
Also I need to have each seperate item put into a user order history database.
I'm thinking an array with for each? maybe?
but not sure how to get the info into one fro mthe way it is now.
Thank you
Posted: Mon Sep 24, 2007 12:31 pm
by feyd
How are you setting the session variables?
Posted: Mon Sep 24, 2007 12:36 pm
by jramaro
i pull the temporary cart data from database and then convert it to SESSIONS like this :
Code: Select all
$_SESSION['product_id'] = $row['product_id'] ;
$_SESSION['product_name'] = $row['product_name'];
etc
but i have a
Code: Select all
while ($row=mysql_fetch_array($result, MYSQL_ASSOC)) {
so that its echoing out blocks of info for each one.
Posted: Mon Sep 24, 2007 12:45 pm
by feyd
Your existing system supports only one item?
Posted: Mon Sep 24, 2007 12:50 pm
by jramaro
the existing stuff echos them all out and everything is working fine. and displaying the way it should be .
so then they finish ordering it, and i want it to send an email from form and inject the data into a order_history database.
but Im not sure how to break all those down to do that. Ive never used an array on anything like that before so im not sure.
The original way i had made it was for single orders though right.
now everything is converted , except for the mail forms and order history SQL inject.
Posted: Mon Sep 24, 2007 1:12 pm
by feyd
If your session setting code looks exactly like what was posted, it only holds a single item; the last one.
While thankfully I haven't ever needed to write a cart system, I have imagined that I would associate the cart with either their username, email address or session id.. depending on what information is available. It would be stored in a database so it could potentially remain across site browsings. Although after a month or so it would be cleaned out. Anyways, what I'm getting to is how the cart would be handled: it would likely be the same database where order line items were kept.
Orders would be composed of mainly two tables: order number and other global order specific details then the order line items table. The line items table would link to the product table. The order having a sale date-time would change it from a shopping cart to an order.
Posted: Mon Sep 24, 2007 1:21 pm
by jramaro
edit
This post obsolete
Posted: Mon Sep 24, 2007 2:23 pm
by califdon
I don't see where the problem is. If the data is already in a table, you should be able to just query the table and construct your email. What am I missing?
In general, I agree with feyd that probably the easy way to handle unconfirmed/incomplete orders is to mix them in the same table, with a flag that signifies when they are completed/confirmed. Assuming that the great majority of orders do get confirmed. You could have a housekeeping routine that deletes old unconfirmed orders that clearly are no longer needed in the system.
Posted: Mon Oct 01, 2007 9:51 am
by jramaro
The data is in tables , but the problem im having is that the data will be unknown as to how many tables.
because the user can input as much information as they want , it gets put into tables and the nwill be output by email at the end.
Im able to query the tables based on the users 'user_id' , but Im not sure how to make one mail template to output al lthe information.
I have this same idea working in a order_history by echoing out the variables i na while() loop.
but i cant echo it for email so the same way wont work.
Also do i assign the whole sequence of information as one variable like $message for the mail?
because when i did that , the variable $message is overwritten each time only displaying the very last
i have it working to display to webpage, but Im not sure how to make this work in email like that
Thank you for any help
Posted: Mon Oct 01, 2007 9:59 am
by feyd
jramaro wrote: but i cant echo it for email so the same way wont work.
Why? It's fundamentally the same.
jramaro wrote: because when i did that , the variable $message is overwritten each time only displaying the very last
Your looping code is wrong then. Likely, you're assigning, not concatenating.
Posted: Mon Oct 01, 2007 10:06 am
by jramaro
So when i have all the formatting set up with
Code: Select all
echo "Product Name: " . $product_name . "\r\n" ;
echo "Quantity: " . $quantity . "\r\n" ;
echo "Subtotal: " . $subtotal . "\r\n" ;
echo "Shipping Charges: " $shipping_charges . "\r\n" ;
echo " TOTAL: " . $total . "\r\n" ;
how do i assign this as a $message that i can use when i send mail?
( a $message that wont overwrite itself you know what i mean)
Posted: Mon Oct 01, 2007 10:32 am
by feyd
Posted: Tue Oct 02, 2007 7:53 am
by jramaro
I understand concatenating, i just dont understand how to apply it to this scenario.
if I will have an unknown number of information tables to concatenate.
do you mean something as far as
Code: Select all
echo $message = " some line of info" ;
echo $message .= "some more info" ;
echo $message .= " etc etc" ;
thats what im visualizing roughly lol
Ive never had to output an email like this
am i headed in the right direction?
Thank you
Posted: Tue Oct 02, 2007 9:04 am
by Stryks
Well, that should work. You tried it?
You might not want to echo on each line. If you remove the echo from the front of each line you can then just
How are you building the output though? I'm assuming you are looping through database records adding to $message as you go, and adding the item values to get your subtotal?
Posted: Tue Oct 02, 2007 11:23 am
by califdon
jramaro wrote:The data is in tables , but the problem im having is that the data will be unknown as to how many tables.
because the user can input as much information as they want , it gets put into tables and the nwill be output by email at the end.
Im able to query the tables based on the users 'user_id' , but Im not sure how to make one mail template to output al lthe information.
I have this same idea working in a order_history by echoing out the variables i na while() loop.
but i cant echo it for email so the same way wont work.
Also do i assign the whole sequence of information as one variable like $message for the mail?
because when i did that , the variable $message is overwritten each time only displaying the very last
i have it working to display to webpage, but Im not sure how to make this work in email like that
Thank you for any help
Wait a minute--you don't know how many tables??? Surely you're not putting every order into its own table? That would be exceedingly bad design.