Order Number
Customer
DVDName
DateOut
DateDue
DateIn
// Connect to server or return an error
$link = mysql_connect("localhost", "mysqlapp", "pw1")
or die("Could not connect: " . mysql_error());
// Select database or return an error
mysql_select_db("DVDRentals", $link)
or die("Unable to select database: . mysql_error()");
// Initialize variables with parameters retrieved from the form
$command = null;
$transactionId = null;
if(isset($_POST["command"]))
$command = $_POST["command"];
if(isset($_POST["transaction_id"]))
$transactionId = $_POST["transaction_id"];
// Processes the delete command
if($transactionId != null)
{
if(strcmp("delete", $command) == 0)
{
include "delete.php";
}
}
// Construct the SQL statement
$selectSql = "SELECT ".
"Transactions.TransID, ".
"Transactions.OrderID, ".
"Transactions.DVDID, ".
"Transactions.DateOut, ".
"Transactions.DateDue, ".
"Transactions.DateIn, ".
"Customers.CustFN, ".
"Customers.CustLN, ".
"DVDs.DVDName ".
"FROM Transactions, Orders, Customers, DVDs ".
"WHERE Orders.OrderID = Transactions.OrderID ".
"AND Customers.CustID = Orders.CustID ".
"AND DVDs.DVDID = Transactions.DVDID ".
"ORDER BY Transactions.OrderID DESC, Customers.CustLN ASC, ".
"Customers.CustFN ASC, ".
"Transactions.DateDue DESC, DVDs.DVDName ASC;";
// Execute the SQL query
$result = mysql_query($selectSql, $link);
if(!$result)
die("Invalid query: ".mysql_error()." ".$selectSql);
// Loop through the result set
while($row = mysql_fetch_array($result))
{
// Retrieve the columns from the result set into local variables
$transId = $row["TransID"];
$orderId = $row["OrderID"];
$dvdId = $row["DVDID"];
$dateOut = $row["DateOut"];
$dateDue = $row["DateDue"];
$dateIn = $row["DateIn"];
$custFirstName = $row["CustFN"];
$custLastName = $row["CustLN"];
$dvdName = $row["DVDName"];
// Convert nulls to empty strings and format the data
$customerName = "";
$dateOutPrint = "";
$dateDuePrint = "";
$dateInPrint = "";
if($custFirstName != null)
$customerName .= $custFirstName." ";
if($custLastName != null)
$customerName .= $custLastName;
if($dvdName == null)
$dvdName = "";
$dateFormat = "m-d-Y";
if($dateOut != null)
$dateOutPrint = date($dateFormat, strtotime($dateOut));
if($dateDue != null)
$dateDuePrint = date($dateFormat, strtotime($dateDue));
if(strcmp($dateIn, "0000-00-00") != 0)
$dateInPrint = date($dateFormat, strtotime($dateIn));
// Print each value in each row in the HTML table
?>
}
// close Close the database connection and the HTML elements
mysql_close($link);
?>