誰かが助けてくれることを願っています。
私のコードは以下のとおりです。私が望んでいるのは、ユーザーがフォームを送信したときに、選択したオプション値がドロップダウン リストの一番上に残ることです。
どんな助けでも大歓迎です。
<?php require_once('Connections/reps.php'); ?>
<?php function GetPercent ($amount, $total)
{
$count1 = $amount / $total;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
return $count;
}
$countdate = time();
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_orders = 10;
$pageNum_orders = 0;
if (isset($_GET['pageNum_orders'])) {
$pageNum_orders = $_GET['pageNum_orders'];
}
$startRow_orders = $pageNum_orders * $maxRows_orders;
mysql_select_db($database_reps, $reps);
$query_orders = "SELECT
orders.ID AS ID,
customers.`Name` AS customerName,
products.ProductName AS product,
orders.Quantity AS Quantity,
orders.SalesPrice AS SalesPrice,
orders.Price AS Price,
orders.paid AS paid,
orders.AgeOfPayment AS AgeOfPayment,
orders.orderDate AS orderDate,
products.Price AS productPrice,
staff.StaffName AS staffMember,
orders.bonus AS bonus
FROM
orders
INNER JOIN staff AS staff ON orders.staffMember = staff.ID
INNER JOIN products AS products ON orders.product = products.ID
INNER JOIN customers AS customers ON orders.customerName = customers.ID
WHERE
1 = 1 ";
//The above where makes the where true
// The below takes the customer name from the select input and filters based on selection. Filters the order by
if (isset($_GET['customerName2']) && $_GET['customerName2'] != 'FALSE' )
{
$query_orders .= "AND customerName = '" .$_GET['customerName2']."' ";
}
// This makes sure the product is not false and filters
if (isset($_GET['product']) && $_GET['product'] != 'FALSE')
{
$query_orders .= "AND product = '" .$_GET['product']."' ";
}
// The below filters hte Customer Name
if (isset($_GET['customerName'])&& $_GET['customerName'] != 'FALSE') {
$query_orders .= "ORDER BY '".$_GET['customerName']."' ";
}
echo "$query_orders <br /> <br />";
$query_limit_orders = sprintf("%s LIMIT %d, %d", $query_orders, $startRow_orders, $maxRows_orders);
$orders = mysql_query($query_limit_orders, $reps) or die(mysql_error());
$row_orders = mysql_fetch_assoc($orders);
if (isset($_GET['totalRows_orders'])) {
$totalRows_orders = $_GET['totalRows_orders'];
} else {
$all_orders = mysql_query($query_orders);
$totalRows_orders = mysql_num_rows($all_orders);
}
$totalPages_orders = ceil($totalRows_orders/$maxRows_orders)-1;
$queryString_orders = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_orders") == false &&
stristr($param, "totalRows_orders") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_orders = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_orders = sprintf("&totalRows_orders=%d%s", $totalRows_orders, $queryString_orders);
$paid = $row_orders['paid'];
mysql_select_db($database_reps, $reps);
$query_customers = "SELECT Name, ID FROM customers WHERE Status = 'Active'";
$customers = mysql_query($query_customers, $reps) or die(mysql_error());
$row_customers = mysql_fetch_assoc($customers);
$totalRows_customers = mysql_num_rows($customers);
mysql_select_db($database_reps, $reps);
$query_products = "SELECT * FROM products";
$products = mysql_query($query_products, $reps) or die(mysql_error());
$row_products = mysql_fetch_assoc($products);
$totalRows_products = mysql_num_rows($products);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("models/header.php");
?>
</head>
<body>
<div id='wrapper'>
<div id='top'>
<div id='logo'></div>
</div>
<div id='content'>
<div id='left-nav'>
<?php include("left-nav.php"); ?>
</div>
<div id='main'> <?php echo " Hi, $loggedInUser->displayname. Here is where you will be able to view orders from a managers perspective. " ?>
<div id = "filtertable">
<FORM METHOD="GET" ACTION="<?php ?>">
<table border="10" cellpadding="5" cellspacing="5">
<tr>
<td align="center">Order By</td>
<td> <select name="customerName">
<option value="FALSE">Select how to Order By</option>
<option value="ID">Order ID</option>
<option value="customerName">Customer Name</option>
<option value="product">Product</option>
<option value="orderDate">Order Date</option>
<option value="paid">Paid?</option>
</select></td>
</tr>
<tr>
<td align="center">Customer Name</td>
<td><select name="customerName2">
<option value="FALSE" >Select the Customer Name</option>
<?php
do {
?>
<option value="<?php echo $row_customers['ID']?>" ><?php echo $row_customers['Name'];?></option>
<?php
} while ($row_customers = mysql_fetch_assoc($customers));
?>
</select></td>
</tr>
<td align="center">Product</td>
<td><select name="product">
<option value="FALSE" >Select a Product</option>
<?php
do {
?>
<option value="<?php echo $row_products['ID']?>" >
<?php echo $row_products['ProductName']?>
</option>
<?php
} while ($row_products = mysql_fetch_assoc($products));
?>
</select></td>
</tr>
<td align="center">Order Date</td>
<td><input type="text" name="email" value="" size="25" /></td>
</tr>
<td align="center">Paid?</td>
<td><input type="text" name="email" value="" size="25" />
</td>
</tr>
<td colspan="2" align="center">
<INPUT TYPE="SUBMIT" VALUE="Submit Filter" NAME="B1" /> </td>
</tr>
</table>
<P> </P>
</FORM>
</div>
<div id ="orderstable">
<table border="10" cellpadding="5" cellspacing="5">
<tr>
<th>Order ID</th>
<th>Customer Name</th>
<th>Product</th>
<th>Quantity</th>
<th>Sales Price (€)</th>
<th>Total Sale (€)</th>
<th>List Price (€)</th>
<th>Price Difference (€)</th>
<th>% Difference</th>
<th>Sold By</th>
<th>Order Date</th>
<th>Age of Payment</th>
<th>Paid?</th>
<th>Bonus %</th>
<th>Bonus Amount (€)</th>
</tr>
<?php do { ?>
<tr>
<td align="center" valign="middle"><?php echo $row_orders['ID']; ?></td>
<td align="center" valign="middle"><?php echo $row_orders['customerName']; ?></td>
<td align="center" valign="middle"><?php echo $row_orders['product']; ?></td>
<td align="center" valign="middle"><?php echo $row_orders['Quantity']; ?></td>
<td align="center" valign="middle"><?php echo "€"; echo number_format($row_orders['SalesPrice'], 2); ?></td>
<td align="center" valign="middle"><?php $first_multiply = $row_orders['Quantity'];
$second_multiply = $row_orders['SalesPrice'];
$multiply_total = $first_multiply * $second_multiply;
echo "€"; echo number_format(($multiply_total) , 2); ?></td>
<td align="center" valign="middle"><?php echo "€"; echo number_format($row_orders['Price'] ,2); ?></td>
<td align="center" valign="middle"><?php echo "€"; $first_number = $row_orders['Price'];
$second_number = $row_orders['SalesPrice'];
$sum_total = $second_number - $first_number;
echo number_format(($sum_total) ,2); ?></td>
<td align="center" valign="middle"><?php $percent = GetPercent($sum_total, $row_orders['Price']);
echo $percent."%"; ?></td>
<td align="center" valign="middle"><?php echo $row_orders['staffMember']; ?></td>
<td align="center" valign="middle"><?php echo date('d/m/Y', $row_orders['orderDate']); ?></td>
<td align="center" valign="middle"><?php
$currentorderdate = $countdate - $row_orders['orderDate'];
$age = ($currentorderdate / 86400);
$ageoforder = round($age, 0);
echo $ageoforder;
?> day(s)</td>
<td align="center" valign="middle"><?php
if ($row_orders['paid'] == Yes) {
echo $row_orders['paid'];
} else {
echo "No";
}
?></td>
<td align="center" valign="middle"><?php
echo $row_orders['bonus']; ?>%</td>
<td align="center" valign="middle"><?php
$bonustotal = (($multiply_total/100) * ($row_orders['bonus']));
if ($percent > 0 && $ageoforder-1 < 90 ) {
echo "€"; echo number_format($bonustotal ,2);
} else {
echo "€"; echo 0;
}
?></td>
</tr>
<?php } while ($row_orders = mysql_fetch_assoc($orders));?>
</table>
<table border="0">
<tr>
<td><?php if ($pageNum_orders > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_orders=%d%s", $currentPage, 0, $queryString_orders); ?>">First</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_orders > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_orders=%d%s", $currentPage, max(0, $pageNum_orders - 1), $queryString_orders); ?>">Previous</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_orders < $totalPages_orders) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_orders=%d%s", $currentPage, min($totalPages_orders, $pageNum_orders + 1), $queryString_orders); ?>">Next</a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_orders < $totalPages_orders) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_orders=%d%s", $currentPage, $totalPages_orders, $queryString_orders); ?>">Last</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
</div>
</div>
<div id ="bottompart">
<div id='bottom'></div>
</div>
</div>
</div>
</body>
</html><?php
mysql_free_result($orders);
mysql_free_result($staff);
mysql_free_result($products);
?>