我一直在搜索此代码一整天,但没有运气,我在谷歌搜索时发现了一个代码,显然它不起作用,所以我以自己的方式对其进行了编辑,但我仍然没有让它真正起作用,所以,如果有人帮助我处理这段代码,我会很高兴的。
我想要的是当我选择一个单选按钮并点击进入下一页时,我看到应该根据单选按钮显示我的数据库数据。它就像一个数据库过滤器,它过滤掉我的数据库数据。
所以首先这里是第一页...... FILTERPAGE.HTML
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>FILTER PAGE</title>
</head>
<body>
<form action="search.php" method="post" name="filter_option">
<table width="100%" border="0">
<tr>
<td>
<label>
<input name="filter_options" type="radio" id="filter_options_0" value="default_filter" checked>
Default</label>
</td>
<td><label>
<input type="radio" name="filter_options" value="special_id_filter" id="filter_options_1">
Special ID</label></td>
<td><label>
<input type="radio" name="filter_options" value="company_name_filter" id="filter_options_2">
Company Name</label></td>
<td><label>
<input type="radio" name="filter_options" value="brand_name_filter" id="filter_options_3">
Brand Name</label></td>
<td><label>
<input type="radio" name="filter_options" value="model_id_filter" id="filter_options_4">
Model ID</label></td>
<td><label>
<input type="radio" name="filter_options" value="colour_filter" id="filter_options_5">
Colour</label></td>
<td><label>
<input type="radio" name="filter_options" value="size_filter" id="filter_options_6">
Size</label></td>
<td><label>
<input type="radio" name="filter_options" value="frame_type_filter" id="filter_options_7">
Frame Type</label></td>
<td><label>
<input type="radio" name="filter_options" value="frame_for_filter" id="filter_options_8">
Frame For</label></td>
<td><label>
<input type="radio" name="filter_options" value="quantity_filter" id="filter_options_9">
Quantity</label></td>
<td><label>
<input type="radio" name="filter_options" value="price_filter" id="filter_options_10">
Price</label></td>
</tr>
</table>
<input name="submit" type="submit">
</form>
</body>
</html>
现在是第二个,它是 PHP 的东西............ SEARCH.PHP
<?php
mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("stock_entry") or die(mysql_error());
$filteroption= $_POST['filter_options'];
//To use different queries while searching
if ($filteroption == 'default_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'id'";
}
else if ($filteroption == 'special_id_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'special_id'";
}
else if ($filteroption == 'company_name_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'company_name'";
}
else if ($filteroption == 'brand_name_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'brand_name'";
}
else if ($filteroption == 'model_id_filter')
{
$queres = "SELECT * FROM stock_entry_spectacles ORDER BY 'model_id'";
}
$query = $queres;
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)){
echo "<table class='data' border='0' cellspacing='2' align='center'>
<tr>
<td align='center' class='special_id'><input type='text' name='id' value='".$row['special_id']."'></td>
<td align='center' class='company_nametd'><input type='text' name='company_name' value='".$row['company_name']."'></td>
<td align='center' class='brand_namestd'> <input type='text' name='brand_name' value='".$row['brand_name']."'></td>
<td align='center' class='model_idtd'> <input type='text' name='model_id' value='".$row['model_id']."'></td>
<td align='center' class='colour_selecttd'> <input type='text' name='colour_select' value='".$row['colour_select']."'></td>
<td align='center' class='size_selecttd'> <input type='text' name='size_select' value='".$row['size_select']."'></td>
<td align='center' class='type_selecttd'><input type='text' name='type_select' value='".$row['type_select']."'></td>
<td align='center' class='for_selecttd'> <input type='text' name='for_select' value='".$row['for_select']."'></td>
<td align='center' class='quantitytd'> <input type='text' name='quantity' value='".$row['quantity']."'></td>
<td align='center' class='pricetd'> <input type='text' name='price' value='".$row['price']."'></td>
<tr>
</table>";
}
?>
最后但并非最不重要的Mysql结构......
数据库名称:stock_entry
表的表结构stock_entry_spectacles
CREATE TABLE IF NOT EXISTS `stock_entry_spectacles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`special_id` int(225) DEFAULT NULL,
`company_name` text COLLATE utf8_unicode_ci,
`brand_name` text COLLATE utf8_unicode_ci,
`model_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_polish_ci DEFAULT NULL,
`colour_select` text COLLATE utf8_unicode_ci,
`size_select` int(11) DEFAULT NULL,
`type_select` text COLLATE utf8_unicode_ci,
`for_select` text COLLATE utf8_unicode_ci,
`quantity` int(11) DEFAULT NULL,
`price` int(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=6 ;
转储表的数据stock_entry_spectacles
INSERT INTO `stock_entry_spectacles` (`id`, `special_id`, `company_name`, `brand_name`, `model_id`, `colour_select`, `size_select`, `type_select`, `for_select`, `quantity`, `price`) VALUES
(1, NULL, 'Titan', 'abc', '123', 'GunMetal', 50, 'Metal', 'Male', 2, NULL),
(2, NULL, 'AO Specs', 'def', '456', 'Black', 48, 'Metal', 'Male', 6, 500),
(3, NULL, 'Sinora', 'ghi', '789', 'Blue', 13, 'broad sided', 'Female', 3, 460),
(4, NULL, 'Tommy', 'jkl', '963', 'GunMetal', 40, 'Shell', 'Male', 8, 800),
(5, 14873273, 'Manav', 'mno', '852', 'Black', 50, 'Metal', 'Male', 5, 120);
请任何人尝试帮助我,因为我的一个项目需要此代码....