Jump to content

Recommended Posts

http://www.wmptest.com/hrfinal/additem.html

 

 

<?php
session_start();

if(isset($_GET['clearlist'])){

session_destroy();

}else{


$item_to_add = $_GET['item'];
$count = count($_SESSION['items']);


if ( ! isset ( $_SESSION['items'] ) )
{
    echo "no items set... adding item";
   $_SESSION['items'] = array ( $_GET['item'], 1);
   
} else {

if ( ! in_array ( $_GET['item'], $_SESSION['items'] ) )
     {
     echo "there is items, but this item doesn't exist";
     
     $_SESSION['items'][] = $_GET['item'];
     $_SESSION['items'][$_GET['item']][] = 1;

     } else {
     echo "there is items, and this item exist, so adding to qty";
     $_SESSION['items']['$item_to_add'][] = $_SESSION['items']['$item_to_add'][1] + 1;
     }
     
     
}

if ( isset ( $_SESSION['items'] ) )

{

} else {


echo "No Items exist!";

     
}

}
?>

 

Okay, I know everything is finally working.. I just need to know how I would go about displaying the items.

 

If anyone has an idea of what I should be looking into please post.

 

Thanks,

Justin :)

 

 

Link to comment
https://forums.phpfreaks.com/topic/141985-how-would-i-go-about-displaying-this/
Share on other sites

I tried this

 

<?php
session_start();

if(isset($_GET['clearlist'])){

session_destroy();

}else{


$item_to_add = $_GET['item'];
$count = count($_SESSION['items']);


if ( ! isset ( $_SESSION['items'] ) )
{
    echo "no items set... adding item";
   $_SESSION['items'] = array ( $_GET['item'], 1);
   
} else {

if ( ! in_array ( $_GET['item'], $_SESSION['items'] ) )
     {
     echo "there is items, but this item doesn't exist";
     
     $_SESSION['items'][] = $_GET['item'];
     $_SESSION['items'][$_GET['item']][] = 1;

     } else {
     echo "there is items, and this item exist, so adding to qty";
     $_SESSION['items']['$item_to_add'][] = $_SESSION['items']['$item_to_add'][1] + 1;
     }
     
     
}

if ( isset ( $_SESSION['items'] ) )

{

foreach($_SESSION['items'] AS $key){
           foreach($_SESSION['items'][1] AS qty){
           
               echo $key . "x" . $qty ."<br />";
               }
               
}


} else {


echo "No Items exist!";

     
}

}
?>

 

But this reports an error I have never seen before..

 

Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /homepages/29/d119570661/htdocs/wmptest.com/hrfinal/inc.additem.php on line 42

Okay im trying a different way, but it doesn't work.. This is making me frustrated.

 

<?php
session_start();

if(isset($_GET['clearlist'])){

session_destroy();

}else{


$item_to_add = $_GET['item'];
$count = count($_SESSION['items']);


if ( ! isset ( $_SESSION['items'] ) )
{
    echo "no items set... adding item";
   $_SESSION['items'] = array ( $_GET['item']."|1");
   
} else {

if ( ! in_array ( $_GET['item'], $_SESSION['items'] ) )
     {
     echo "there is items, but this item doesn't exist";
     
     $_SESSION['items'] = $_GET['item']."|1";


     } else {
     echo "there is items, and this item exist, so adding to qty";

     $explosive = $_SESSION['items'][$item_to_add];
     $pieces = explode("|", $explosive);
     $newqty = $pieces[1] + 1;
     $item = $pieces[0];
     $_SESSION['items'][$item_to_add] = $item."|".$newqty;
     }
     
     
}

if ( isset ( $_SESSION['items'] ) )

{

foreach($_SESSION['items'] AS $key){

             $getiteminfo = explode("|", $key);
             $item = $getiteminfo[0];
             $qty = $getiteminfo[1];
               echo "<br>".$item ." x ".$qty."<br />";
               }
               



} else {


echo "No Items exist!";

     
}

}
?>

 

to see the gaggle of errors just go here: http://www.wmptest.com/hrfinal/additem.html

 

 

try

<?php
session_start();
if(isset($_GET['clearlist'])){
session_destroy();
}else{
$item_to_add = $_GET['item'];
if ( ! isset ( $_SESSION['items'] ) )
{
	echo "no items set... adding item";
	$_SESSION['items'][$item_to_add] = 1;
} else {
	if ( ! isset($_SESSION['items'][$item_to_add] ) )
	{
		echo "there is items, but this item doesn't exist";
		$_SESSION['items'][$item_to_add] = 1;
	} else {
		echo "there is items, and this item exist, so adding to qty";
		$_SESSION['items']['$item_to_add']++;
	}
}
if ( isset ( $_SESSION['items'] ) )
{
	foreach($_SESSION['items'] AS $key => $qty){
		echo $key . "x" . $qty ."<br />";
	}
} else {
	echo "No Items exist!";
}
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.