I have been banging my head on this for a few days I am finally giving in and am now seeking help.
I have these 2 sets of code that works
This one calls the one below and passes "IS NULL" to the other function and the other function displays the data.
<html>
<head>
<link rel="stylesheet" href="style.css">
<title>My PHP</title>
</head>
<body>
<div class="body">
<?php
require_once 'ShowInventory.php';
DBShowInventory("IS NULL");
?>
</div>
</body>
</html>
<?php
function DBShowInventory($WhichInventory){
require_once 'connection.php';
$conn = Connect();
$result = $conn->query("select Description, PartNumber, Serial, Store, Cost, MSRP, DateReceived from inventory where DateSold $WhichInventory;");
echo "</br></br></br>\r\n";
echo "<table class=\"center\"> \r\n";
echo ' <tr>';
echo ' <th>Description</th>';
echo ' <th>Part Number</th>';
echo ' <th>Serial</th>';
echo ' <th>Store</th>';
echo ' <th>Cost</th>';
echo ' <th>MSRP</th>';
echo ' <th>DateReceived</th>';
echo " </tr> \r\n";
while ($row = $result->fetch_assoc()) {
unset($Description, $PartNumber, $Serial, $Store, $Cost, $MSRP, $DateReceived);
$Description = $row['Description'];
$PartNumber = $row['PartNumber'];
$Serial = $row['Serial'];
$Store = $row['Store'];
$Cost = $row['Cost'];
$MSRP = $row['MSRP'];
$DateReceived = $row['DateReceived'];
echo "<tr> \r\n";
echo "<td>" .$Description. "</td> \r\n";
echo "<td>" .$PartNumber. "</td> \r\n";
echo "<td>" .$Serial. "</td> \r\n";
echo "<td>" .$Store. "</td> \r\n";
echo "<td>";
echo "₱";
echo number_format($Cost,2,'.',',');
echo "</td> \r\n";
echo "<td>";
echo "₱";
echo number_format($MSRP,2,'.',',');
echo "</td> \r\n";
echo "<td>" .$DateReceived. "</td> \r\n";
echo "</tr> \r\n";
}
echo "</table> \r\n";
}
?>
What I am hoping to do is to flip the logic around and have the script on top to do the displaying and use the script in the bottom to do the database query only. This way I can use this function over and over for different things.
I tried doing this but all I get is one record repeated 7 times.
<?php
function DBLookup($DateSold){
require_once 'connection.php';
$conn = Connect();
$result = $conn->query("select Description, PartNumber, Serial, Store, Cost, MSRP, DateReceived from inventory where DateSold $DateSold;");
$row = (array) $result->fetch_assoc();
return $row;
}
?>
This is the script I wanted to use to process $row
<html>
<head></head>
<body>
<?php
require_once 'GetMultiRecordFromDB.php';
$row=DBLookup("IS NULL");
echo "</br></br></br>\r\n";
echo "<table class=\"center\"> \r\n";
echo ' <tr>';
echo ' <th>Description</th>';
echo ' <th>Part Number</th>';
echo ' <th>Serial</th>';
echo ' <th>Store</th>';
echo ' <th>Cost</th>';
echo ' <th>MSRP</th>';
echo ' <th>DateReceived</th>';
echo " </tr> \r\n";
foreach($row as $rowdata) {
unset($Description, $PartNumber, $Serial, $Store, $Cost, $MSRP, $DateReceived);
$Description = $rowdata['Description'];
$PartNumber = $rowdata['PartNumber'];
$Serial = $rowdata['Serial'];
$Store = $rowdata['Store'];
$Cost = $rowdata['Cost'];
$MSRP = $rowdata['MSRP'];
$DateReceived = $rowdata['DateReceived'];
echo "<tr> \r\n";
echo "<td>" .$Description. "</td> \r\n";
echo "<td>" .$PartNumber. "</td> \r\n";
echo "<td>" .$Serial. "</td> \r\n";
echo "<td>" .$Store. "</td> \r\n";
echo "<td>";
echo "₱";
echo number_format($Cost,2,'.',',');
echo "</td> \r\n";
echo "<td>";
echo "₱";
echo number_format($MSRP,2,'.',',');
echo "</td> \r\n";
echo "<td>" .$DateReceived. "</td> \r\n";
echo "</tr> \r\n";
}
echo "</table> \r\n";
?>
</body>
</html>
Thanks guys looking forward to your reply.