phpanon Posted March 11, 2008 Share Posted March 11, 2008 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 https://forums.phpfreaks.com/topic/95679-id-to-only-appear-if-value-is-not-null/ Share on other sites More sharing options...
discomatt Posted March 11, 2008 Share Posted March 11, 2008 if (empty($formerID) ) echo 'no related orders'; else echo $formerID; Link to comment https://forums.phpfreaks.com/topic/95679-id-to-only-appear-if-value-is-not-null/#findComment-489864 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.