给定一个MYSQL数据库,我有一个包含大量条目的表,结构如下:PHP复选框检索数据
string |类型
字段“type”可以在数据库中有4个值(a,b,c,d)。
我想使用复选框的形式来检索数据库中的所有字符串通过检查四个可能的值之一。
所有我到目前为止是这样的片的PHP代码:
<?
$objConnect = mysql_connect("localhost","root","****") or die("No DB to select.");
$objDB = mysql_select_db("exercises");
$strSQL = "SELECT * FROM entries WHERE type = '".$_POST["type"]."'";
$objQuery = mysql_query($strSQL);
?>
<?
$checkbox = array();
if (isset($_POST["type"])){
$checked = $_POST["type"];
foreach ($checked as $value) {
echo "$value"."</br>";
}
}
else{
echo "Please select at least one type.";
}
?>
的问题是,此代码只返回类型值A,B,c,d和不条目中的字符串数据库。
任何人都可以告诉我如何实际访问我的数据库条目并检索对应于表单中选中类型的字符串值吗? 谢谢!
PS:这里是我想要使用的形式HTML:
<html>
<head>
<title>select</title>
<META http-equiv="Content-Type" content="text/html; charset=latin-1">
</head>
<body bgcolor="#F5FAE6">
<center>
<h2><p align="center">Make your test</p></h2>
</center>
<br><br>
<form action="output.php" method="POST">
✔ Select the <b>type(s) of exercise</b> you need:<br /><br />
<table border="1" cellpadding='4' cellspacing='4' style='border-collapse: collapse' bordercolor='#9999DD'>
<tr><td><input type="checkbox" name="type[]" value="abc"/> multiple choice</td></tr>
<tr><td><input type="checkbox" name="type[]" value="error"/> mistake correction</td></tr>
<tr><td><input type="checkbox" name="type[]" value="cloze"/> cloze</td></tr>
<tr><td><input type="checkbox" name="type[]" value="makeq"/> make a question</td></tr>
<tr><td><input type="checkbox" name="type[]" value="trans"/> translate (IT-->EN)</td></tr>
</table>
<p align="center">
<input type="submit" name= "get" value="get your entries!"/>
</p>
</form>
</body>
</html>
数据库连接到哪里等? –
你的数据库连接/查询代码在哪里? – Sean
你甚至有一个SQL查询?请显示使用什么SQL查询您尝试迄今为止,或作为前两个意见建议,显示使用您的连接 – Krimson