Jump to content

ID to only appear if value is not null


phpanon

Recommended Posts

Hello there.

 

I have a list of orders in a table. Some orders that were previously rejected but then re-submitted have a formerID that relates to the rejected order.

What I want is that if an order has a formerID then display that to the user, if not then display "no related orders" or something.

 

Here is my code

 

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

require "connect.php";
$query = "SELECT DISTINCT o.orderID, p.formerID FROM orders o, productorder p WHERE p.orderID = o.orderID AND p.status = 'Complete' AND o.empID = ".$_SESSION['empID'];
$result = mysql_query ($query, $connection) or die ("Unable to perform query<br>$query");
?>
<!DOCTYPE HTML PUBLIC "//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Past Orders</title>
<link rel="stylesheet" type="text/css"
href="mystylelogin.css" />

</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">Past Orders</div>

<div id="OrdersBasketTable">
<table border="0" width="100%">
<hr />
<tr>
	<th width="100">Order Number</th>
	<th colspan="2" align="right">Related Orders</th>
</tr>
<?php
while($row=mysql_fetch_array($result))
{ $total2 = 0; ?>
	<tr>
		<td align="center"><h2><strong><?php echo $row['orderID']?></strong></h2></td>
		<td>
		<table border="0"width="100%">
		<tr>
			<th width="25%" align="left">Product</th>
			<th width="10%" align="left">Price</th>
			<th width="10%" align="left">Quantity</th>
			<th width="18%" align="left">Date Made</th>
			<th width="14%" align="left">Date Approved</th>
			<th width="13%" align="left">Total</th>
		</tr>
		<tr>

<?php
$query2 = "SELECT * FROM orders o, productorder e, product p WHERE o.orderID = e.orderID AND p.URN = e.URN AND e.status = 'Complete' AND o.orderID = '".$row['orderID']."'";
$result2 = mysql_query ($query2, $connection) or die ("Unable to perform query<br>$query2");

			while($row2=mysql_fetch_array($result2))
			{ ?>
  		  <tr>
					<td><a href="productOrder.php?URN=<?php echo $row2['URN']?>"><?php echo $row2['productName']?></td>
					<td>£<?php echo $row2['price']?></td>
					<td align="center"><?php echo $row2['quantity']?></td>
					<td><?php echo $row2['date']?></td>
					<td><?php echo $row2['apprDate']?></td>

					<?php $total = $row2['quantity'] * $row2['price']; ?>
					<td>£<?php echo $total ?></td>
					<?php $total2 = $total2 + $total ?>
					<td><?php echo $row['formerID'];?></td>
  		  </tr>
				<?php
			} ?>
			</td>
			</tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td><strong>Total</strong></td>
			<td>£<?php echo $total2 ?></td>
			<td></td>
  </table>
			<?php
	} ?>
</table>
</td>
</table>
</div>
</body>
</html>

 

Thanks everyone

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.