Grouping $-Session outputs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
deadman6
Forum Newbie
Posts: 4
Joined: Wed Sep 14, 2011 1:51 pm

Grouping $-Session outputs

Post by deadman6 »

So i have 3 form fields. Each time they are submitted the inputs are display as well as the previous inputs are display. Each time the set of inputs are submitted, each output is put into a div with the same name. That name is increased by one each time. So the first time submit is hit there is 3 <div id="id1"></div> then second submit is hit there are 3 <div id="id1"></div> and 3 <div id="id2"></div> .

What i need to do is wrap each group of <div id="id(X)"></div>. So if the submit button has been hit twice there should be :

Code: Select all

<div id="wrap"> <div id="id1"></div> <div id="id1"></div> <div id="id1"></div> </div> 
<div id="wrap"> <div id="id2"></div> <div id="id2"></div> <div id="id2"></div> </div>
Let me know if it would be easier if i show you have i am getting each <div id="id(X)"></div>
deadman6
Forum Newbie
Posts: 4
Joined: Wed Sep 14, 2011 1:51 pm

Re: Grouping $-Session outputs

Post by deadman6 »

Here is my code.. I will make a picture in just a minute...

Code: Select all

<?php session_start(); ?>
<?php
if(!isset($_SESSION['counter'])){
	$_SESSION['counter'] ='1';
} 
if($_POST)
	$_SESSION['name'] .= '<div id="id'.$_SESSION['counter'].'">'.$_POST['name'].'</div>'; 
	echo $_SESSION['name'] ;
?>
<?php if($_POST)
	$_SESSION['email'] .= '<div id="id'.$_SESSION['counter'].'">'.$_POST['email'].'</div>';
	echo $_SESSION['email'] ;  
	 ?> 
<?php if($_POST)
	$_SESSION['phone'] .= '<div id="id'.$_SESSION['counter'].'">'.$_POST['phone'].'</div>';  
	echo $_SESSION['phone'] ;
	 ?>    
<?php if($_POST)
	$_SESSION['counter']++;
?>
<?php if($_POST[reset]) {
	unset($_SESSION['counter']);
	unset($_SESSION['name']);
	unset($_SESSION['email']);
	unset($_SESSION['phone']);
 } ?>

     
<form method="post" action="index.php">
<div id="name">Name:<input type="text" name="name" size="10" /></div>
<div id="email">Armor:<input type="text" name="email" size="10" /></div>
<div id="phone">Strength:<input type="text" name="phone" size="10" /></div>

<input type="submit" name="submitted" value="Submit"/>
<input type="submit" name="reset" value="reset" />
</form>
And here is a img of what i want to happen...
Image
Post Reply