Jump to content

variables in an array


phpanon

Recommended Posts

Hello there,

 

I have a simple internal ordering system.

An order is placed by users and then sent to the manager. The manager must then approve or reject the order.

One of the features of the system is that the user can re-submit rejected orders.

This is done clicking on a button that puts all the products of the rejected order back into the shopping basket array so that products can be removed or added. Along with the products, the rejected orderID is also carried across into the shopping basket so that there is an audit trail that keeps track of relating orders.

At the moment I have got it so that the rejected order (formerID) is carried across with the products but any extra products that are added to the basket do not have the formerID attached to them.

 

Is there anyway of setting the formerID in the shopping basket array to the same value as the record above??

 

Here is my code shopping basket code

<?php
session_start();
if (isset($_SESSION['username']) == false){
	header("Location: login.php");
	exit();
}
require "connect.php";

?>

<!DOCTYPE HTML PUBLIC "//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>View Basket</title>
<link rel="stylesheet" type="text/css"
href="mystylelogin.css" />

<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body>

<?php
switch ($_SESSION['type']) 
{
	case 'user':
    	include ("header.php");
	include ("StationaryMenu.php");
    	break;
  
	case 'admin':
	include ("headerAdminMain.php");
	include ("StationaryMenu.php");
	break;

	case 'manager':
	include ("header.php");
	include ("StationaryMenuManager.php");
	break;
}
?>

<div id="header">Stationary Basket</div>

<div id="OrdersBasketTable">
<hr />
<table width="100%" border ="0">
<tr>
<th width="112">URN</th>
<th width="169">Product</th>
<th width="298">Description</th>
<th width="120">Price</th>
<th width="112">Quantity</th>
<th width "70">Remove</th>
</tr>				
<?php
if (isset ($_SESSION['basket'])) 
{
foreach($_SESSION['basket'] as $key => $product) 
{ ?>
  <tr>
  	<td><div align="center"><?php echo $_SESSION['basket'][$key]['URN']?></div></td>
    <td><?php echo $_SESSION['basket'][$key]['productName']?></td>
	<td><?php echo $_SESSION['basket'][$key]['description']?></td>
    <td><div align="center">£<?php echo $_SESSION['basket'][$key]['price']?></div></td>
	<td><div align="center"><?php echo $_SESSION['basket'][$key]['quantity']?></div></td>
	<td width="70"><div align="center"><a href="removefrombasket.php?URN=<?php echo $product['URN']?>">[-]</a></div></td>
	<td><?php echo $_SESSION['basket'][$key]['formerID']?></td>
  </tr>
<?php }
}
else { ?>
<?php }
?>
<tr>
<td></td>
<td></td>
<td><div align="center"><span class="style1">
  <?php
if(isset($_GET['message1']))
{
	echo $_GET['message1'];
}
if(isset($_GET['message2']))
{
	echo $_GET['message2'];
}
?>
</span></div></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>

<div id="SubmitBtn">
<form name="form1" action="StationaryOrderQuery.php" method="get">
<input name="save" type="submit" id="save" value="Submit Order" />
</form></div>

<div id="EmptyBasket">
<form name="form2" action="emptyBasket.php" method="get">
<input align="right" name="save2" type="submit" id="save2" value="Empty Basket" />
</form></div>

</body>
</html>

 

Here is the code that I use to move the rejected order products into the shopping basket so the order can be re-submitted

<?php
session_start();
if (isset($_SESSION['username']) == false){
	header("Location: login.php");
	exit();
}
require "connect.php";
$orderID = $_GET['orderID'];
$query = "SELECT p.URN, p.productName, p.description, p.price, e.quantity FROM orders o, productorder e, product p WHERE o.orderID = e.orderID AND p.URN = e.URN AND o.orderID = ".$orderID;
$result = mysql_query ($query, $connection) or die ("Unable to perform query<br>$query");

while($row=mysql_fetch_array($result))
{
$product = array();
$product['URN']= $row['URN'];
$product['productName']= $row['productName'];
$product['description']= $row['description'];
$product['price']= $row['price'];
$product['quantity'] = $row['quantity'];
$product['formerID'] = $orderID;

$_SESSION ['count'];

//$_SESSION['basket'] [] = $product;

$found = false;

if (isset ($_SESSION['basket'])) 
{
	foreach($_SESSION['basket'] as $key => $anotherproduct)
	{
		if ($_SESSION['basket'][$key]['URN'] == $_GET['URN']) 
		{
			$found = true;
			$_SESSION['basket'][$key]['quantity'] ++;
			$_SESSION['count'] ++;
		}
	}
}

//add the product to the shopping basket if its not there already
if ($found == false)
{
	$_SESSION['basket'] [] = $product;
	$_SESSION['count'] += 1;
}
}
header("Location: StationaryBasket.php");
exit();
?>

</body>
</html>

 

Thanks to anyone that can help this situation.

Link to comment
Share on other sites

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.