<html>
<head>
<title>Purchase Order Selection Page</title>
<link href="bookstaff.css" rel="stylesheet" type="text/css"/>
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<?php
include("connect.php");
$result = mysql_query("SELECT * FROM purchaseorder ORDER BY poNo DESC";   

$num_results = mysql_num_rows($result);

echo "<table border='1' cellpadding='0' cellspacing='0' width='100%'>";

echo "<tr>";
echo "<td colspan='6'>";
echo "Supplier List";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>No</td>";
echo "<td>PO No</td>";
echo "<td>Supplier Name</td>";
echo "<td>Date</td>";
echo "<td>Total</td>";
echo "<td>Submit</td>";
echo "</tr>";

for ($i=0; $i <$num_results; $i++){

$row = mysql_fetch_array($result);
echo "<form name='form' method='post'>";
echo "<tr>";
echo "<td>";
echo $i+1;
echo "</td>";
$num = $i+1;
echo "<td>";
echo "<input type='hidden' name='poNo".$num."' value='$row[poNo]'>".$row['poNo']."";
echo "</td>";

echo "<td>";
echo "<input type='hidden' name='supName".$num."' value='$row[supName]'>".$row['supName']."";
echo "<input type='hidden' name='supID".$num."' value='$row[supID]'><input type='hidden' name='qtotal".$num."' value='$row[qTotal]'>";
echo "</td>";

echo "<td>";
echo "".$row['poDate']."";
echo "</td>";

echo "<td>".$row['qTotal']."</td>";

echo "<td>";
echo "<input type='button' value='Submit' onclick='get_value(poNo".$num.".value, supName".$num.".value, supID".$num.".value, qtotal".$num.".value);'>";
?>
<script langauge="JavaScript">
function get_value(num, name, ID, total){
opener.document.aform.poNo.value = num;
opener.document.aform.supName.value = name;
opener.document.aform.supID.value = ID;
opener.document.aform.qtotal.value = total;
self.close();
}
</script>
<?php
echo "</td>";
echo "</tr>";
echo "</form>";
}

echo "</table>";
?>
</html>
