Jump to content


Photo

while loop only produces 1 record


  • Please log in to reply
1 reply to this topic

#1 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 13 March 2006 - 01:29 AM

Hey Hey Ya'll,

I have written a 'confirm shipped' script for a company and even though I KNOW there is more than 1 row that should be returning...

Yet it only returns one...

Code:

<?php
session_start();
session_regenerate_id();
include('connect.php');

if (!$_SESSION['is_admin']){
  header("Location: admin_login.php");
  die();
  
}
if ($_GET['orderid']){
  $oid=$_GET['orderid'];
}else{
  $oid=$_POST['orderid'];
}

if (isset($_POST['submit'])){
  
  if (isset($_POST['Y'])){

   $sql=mysql_query("UPDATE Orders SET dispatched='1' WHERE Invoice_Number='$oid'");
   echo "Thank You, The Order has Been Confirmed Shipped";    
}else{
  die('Stopped');
}
}

$get=mysql_query("SELECT p.Name AS name, o.Subtotal AS sub, od.Price AS price, od.Quantity AS quan FROM Products AS p, Order_Details AS od, Orders as o WHERE o.Invoice_Number='$oid' AND o.Invoice_Number=od.Invoice_Number AND od.Product_ID=p.Product_ID") OR DIE (mysql_error());

echo "<table border='.5'>
<tr><td><b>Product</b></td><td><b>Price</b></td><td><b>Quantity</b></td></tr>";

while ($row=mysql_fetch_array($get)){
  echo "<tr><td>{$row['name']}</td><td>{$row['price']}</td><td>{$row['quan']}</td></tr>";
}

echo "</table><br />
<form method='POST' action=\"$PHP_SELF\">
<b>Confirm?</b>&nbsp;&nbsp;&nbsp;&nbsp;<b>Yes:</b><input type='checkbox' name='Y'><br /
<b>No:</b><input type='checkbox' name='N'><br />
<input type='submit' name='submit' value='Confirm'>
<input type='hidden' name='orderid' value=\"$oid\"></form><br />
<a href='ManagersMainMenu.php'>Main Menu</a>";

?>

SQL Schema:

`Orders`
Invoice_Number
Customer_ID
Date_Ordered
Delivery_date
VAT
Subtotal
month
year
dispatched

`Order_Details`
Invoice_Number
Product_ID
Price
Quantity

Thank You :)

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 13 March 2006 - 01:47 AM

Try the query in Mysql command prompt, myphpadmin or other similar tool first. Tweak it until it works and then place it in the PHP code.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users