Jump to content

How would i go about displaying this


justinh

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!";
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.