473,387 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

joining variables together

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

May 29 '06 #1
5 3012
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
May 29 '06 #2
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" <us**@example.net> wrote in message
news:4e*************@individual.net...
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

May 29 '06 #3
Ian Davies wrote:
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


$lines = $_SESSION['line1'].'<br>'.$_SESSION['line2'];
or
$lines = sprintf("%s<br>%s", $_SESSION['line1'], $_SESSION['line2']);
or
$prefix = 'line';
$lines = '';
foreach($_SESSION as $key => $value) {
if( substr($key, 0, strlen($prefix)) == $prefix) {
if( $lines == '' ) $lines = $value;
else $lines = sprintf("%s<br>%s", $lines, $value);
}
}

This assumes that all the lines you want to join together begin with the
tag name 'line'. (e.g. line1, line2, line_foo, etc.)

-david-

May 29 '06 #4
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
May 29 '06 #5
Thanks J.O.
That was what I wanted

"J.O. Aho" <us**@example.net> wrote in message
news:4e*************@individual.net...
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

May 29 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: chris | last post by:
im pretty ne to java script - so please be gentle :) basically what i want to do is construct an action in a function using a variable sent to that function ok - what i want to do is ...
2
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2...
2
by: Paul M | last post by:
Hi, This is on an AS/400 which can be a little strange but I think the basic question is portable. I have a (non-C) program that needs to make series of calls to some C programs/functions....
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
5
by: Ant | last post by:
hi, I'm now using C#. Seeing as though you can declare & initialize or pass a value to a variable on the same line as the declaration, is it still best practice to group all the variables together...
2
by: Coquette | last post by:
Hi all. I'm new here. I wanted to ask your opinion about *joining two tables* from *two different database* together. Is *that* possible? My project requires me to join identical tables from...
1
by: s99999999s2003 | last post by:
hi i have some databse results that are NoneType and DateTimeType. now i have trouble joining these row results together like "|".join(result) as it says cannot join NoneType , DateTimeType . How...
2
by: Supermansteel | last post by:
I am joining these 2 tables together in Access 2003 and can't figure out the exact way of writing this script......Can anyone help? I have the following SQL: SELECT...
3
by: nickvans | last post by:
Hello everyone, I am new to SQL Server, and am having trouble joining several SELECT statements together. I have three SQL Select statements that do separate count operations to get the status...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.