私はこれを独自の列を持つテーブルに整理しようとしていますが、試みるたびに、本当に厄介なものや完全に間違ったものが表示されます。SQLからテーブルを実装するための助けを得ることができれば、それは素晴らしいことです。たとえば、次の画像を見てください。
http://bfast.elementfx.com/design/table.JPG
これがコードです
$dbHost = 'localhost'; // localhost will be used in most cases
$dbUser = 'root';
$dbPass = 'root';
$dbDatabase = 'root'; // the database you put the table into.
$con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error());
mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
$error = array();
$results = array();
if (isset($_GET['search'])) {
$searchTerms = trim($_GET['search']);
$searchTerms = strip_tags($searchTerms); // remove any html/javascript.
if (strlen($searchTerms) < 2) {
$error[] = "Search terms must be longer than 2 characters.";
}else {
$searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
}
// If there are no errors, lets get the search going.
if (count($error) < 1) {
$searchSQL = "SELECT brandname, manufacturer, distributor, modelnumber, date, expirey FROM productlist WHERE ";
// grab the search types.
$types = array();
$types[] = isset($_GET['Brand Name'])?"`brandname` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['Manufacturer'])?"`manufacturer` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['distributor'])?"`distributor` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['modelnumber'])?"`modelnumber` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['E'])?"`E` LIKE '%{$searchTermDB}%'":'';
$types[] = isset($_GET['F'])?"`F` LIKE '%{$searchTermDB}%'":'';
$types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked)
if (count($types) < 1)
$types[] = "`brandname` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked
$andOr = isset($_GET['matchall'])?'AND':'OR';
$searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `brandname`"; // order by title.
$searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}");
if (mysql_num_rows($searchResult) < 1) {
$error[] = "The search term provided {$searchTerms} yielded no results.";
}else {
$results = array(); // the result array
$i = 1;
while ($row = mysql_fetch_assoc($searchResult)) {
$results[] = "{$i}: <b>Brand Name:</b> {$row['brandname']}<br /><b>Distributor:</b> {$row['distributor']}<br /><b>Manufacturer:</b> {$row['manufacturer']} <br /><b>Model Number:</b> {$row['modelnumber']}<br /><b>Certifying Agency:</b> {$row['E']} {$row['F']}<br /><br /><br />";
$i++;
}