session arrays

This may be a simple question for you folks. I have studied books up and down but still no solution.
I have collected some inputs from a form, name and email. Then i have some items from a session input. I can show the result on the screen but I want to mail the session arrays to my mail adr.
The $line could be several lines. Echoing this shows each lines with product id, name and price and all the lines.
Sending the $line in a mail shows the last line, so i think the other lines has been wtitten over. Can someone give me a hint how to make a text string for mail purposes with the rest of the lines ?Yes I have tried for some nights now :)

header(“Cache-control: private”); //IE 6 Fix

if (isset($_SESSION[“item_count”]) && $_SESSION[“item_count”] > 0) {
$total = 0;
for($i=0; $i<$_SESSION[“item_count”]; $i++) {
$line="$ident -,$name, Price:$pri,-,Pieces:$piecesn";

echo “$lines”;

The mail functin is ok, I am receiving without problem but onely one line.

If I am understanding this correctly you would like to make an array into a string. If this is the case then I would suggest the implode() function.

Yes I want a text string:

$line="$ident -,$name, Price:$pri,-,Pieces:$piecesn";

echo “$lines”;

As long as this code is within the loop,- the lines are echoed correctly line by line, so maybe I ned to generate a multi dim array. Moving the echo"lines" out of the loop results in only one (the last) in $line.

try the concatination symbol (.) with the variables.

$line=$ident. ‘-, ‘.$name.’, Price:’.$pri.’,-,Pieces: '.$pieces.‘n’;

Thank you for the answer.
Tested it out but $line still contains the last line. You can test it here

Quick question… Where are these variables coming from. If the original code is at the very top of the page, where are the variables being loaded? If it from a form then you will need to retrieve them with $_GET or $_POST depending on what the form action is (requiered with register_globals = off).

$ident = $_POST[‘ident’];


The variables are coming from the saved session as the customer has filled a basket with product1, product2…and retrived by opening this session.
If you have visited my test shop, this script is retrieving the session (coockie), (page2 in the shop). My problem is that I do not know how to colect the different products (lines) in one array, say $lines[]…for the purpose of sending it as a text string later.
Echo to the screen works fine with an
tag at the end of the $line and as long as echo is inside the loop.

have you looked at array_push?


Thanks again. I will look inti it but sadly, array_push() does not create an array if the array doesn’t exist. So if you’re pushing the first element onto an array, you need to check and create it manually but I am looking into it. Did some test but couldn’t get it working so far.

Array_merge() merges the elements of one or more arrays ($line) together so that the values of one $line are appended to the end of the previous one. It returns the resulting array. I will do my best testing this too. Something like:

$line[]=$line2[$i]($ident. ‘-, ‘.$name.’, Price:’.$pri.’,-,Pieces: '.$pieces.‘n’);

but the index will be the same and probably cause errors…

$line = array();
array_push($line, $whatever_to_go_in_there);

Jeep, that seems to do the job, thank you again.

Sponsor our Newsletter | Privacy Policy | Terms of Service