For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2006 > joining variables together









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author joining variables together
Ian Davies

2006-05-29, 6:58 pm

Hello
I am trying to update a session, ie everytime the page is resubmitted I want
the current selected value from a list to be appended to the old session
value. I have the following code but am unable to get it to work. I dont
know the correct syntac wher I have put the word 'PLUS'.

<?php $_SESSION['savedcomm'] = $_SESSION['savedcomm'] PLUS
$_POST['selectcomm'];?>

I have tried & but this doesnt work, or even && which I have seen in some
script

Help please
Ian



J.O. Aho

2006-05-29, 6:58 pm

Ian Davies wrote:
> Hello
> I am trying to update a session, ie everytime the page is resubmitted I want
> the current selected value from a list to be appended to the old session
> value. I have the following code but am unable to get it to work. I dont
> know the correct syntac wher I have put the word 'PLUS'.
>
> <?php $_SESSION['savedcomm'] = $_SESSION['savedcomm'] PLUS
> $_POST['selectcomm'];?>
>
> I have tried & but this doesnt work, or even && which I have seen in some
> script


$_SESSION['savedcomm'] = $_SESSION['savedcomm'] . $_POST['selectcomm'];



//Aho
Ian Davies

2006-05-29, 6:58 pm

Thanks Aho

sorry I should have added, what if I want each newly added item to the
session to display as seperat lines when returned to a text field?

Ian

"J.O. Aho" <user@example.net> wrote in message
news:4e0flvF1cbjk5U1@individual.net...
> Ian Davies wrote:
want[color=darkred]
some[color=darkred]
>
> $_SESSION['savedcomm'] = $_SESSION['savedcomm'] . $_POST['selectcomm'];
>
>
>
> //Aho



J.O. Aho

2006-05-29, 6:58 pm

Ian Davies wrote:

> sorry I should have added, what if I want each newly added item to the
> session to display as seperat lines when returned to a text field?



$_SESSION['savedcomm'] = $_SESSION['savedcomm'] . "\n" . $_POST['selectcomm'];

This would add new line between the old and new data.

If you want to display it in a html section, then you can use nl2br()
http://www.php.net/manual/en/function.nl2br.php

<h2><?php echo nl2br($_SESSION['savedcomm']); ?></h2>

If you add things to a textarea, then do

<textarea name="thetext" rows="20" cols="80"><?php echo
$_SESSION['savedcomm']; ?></textarea>

Here you don't use the nl2br as the the textarea element does respect the new
line, which isn't done in html otherwise.


//Aho
Ian Davies

2006-05-29, 6:58 pm

Thanks J.O.
That was what I wanted

"J.O. Aho" <user@example.net> wrote in message
news:4e0ksjF1cie9vU1@individual.net...
> Ian Davies wrote:
>
>
>
> $_SESSION['savedcomm'] = $_SESSION['savedcomm'] . "\n" .

$_POST['selectcomm'];
>
> This would add new line between the old and new data.
>
> If you want to display it in a html section, then you can use nl2br()
> http://www.php.net/manual/en/function.nl2br.php
>
> <h2><?php echo nl2br($_SESSION['savedcomm']); ?></h2>
>
> If you add things to a textarea, then do
>
> <textarea name="thetext" rows="20" cols="80"><?php echo
> $_SESSION['savedcomm']; ?></textarea>
>
> Here you don't use the nl2br as the the textarea element does respect the

new
> line, which isn't done in html otherwise.
>
>
> //Aho



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com