0

这是我的表单和 mysql/php 代码。

如果两个复选框都被选中,mysql 不会执行查询。有没有办法让这个表格正常工作?

MySQL

 if (isset($_POST['A']) && !empty($_POST['A'])) {
 $query= "SELECT * FROM (SELECT * FROM myTable WHERE...) as A WHERE Column1='y'";
 }
 if (isset($_POST['B']) && !empty($_POST['B'])) {
 $query= "SELECT * FROM (SELECT * FROM myTable WHERE...) as B WHERE Column2='y'";
 }

形式

<form id="myform1" class="myform1" method="post" name="myform1">
<input type="checkbox" name="A[]" id="A" value="y" />
<input type="checkbox" name="B[]" id="B" value="y" />
<input id="submit" type="submit" name="submit" value="Submit" 
onclick="return submitForm1()" />
</form>

任何帮助表示赞赏。谢谢

4

1 回答 1

0

只是一个建议,它丑陋但简单:

$teamsters = ''; 
$query = '';
if (isset($_POST['A'][0]) && !empty($_POST['A'][0])) {
   $query= "SELECT * FROM (SELECT * FROM myTable WHERE...) as A WHERE Column1='y'";
   $teamsters = ' UNION ';
}
if (isset($_POST['B'][0]) && !empty($_POST['B'][0])) {
   $query .= $teamsters . "SELECT * FROM (SELECT * FROM myTable WHERE...) as B WHERE Column2='y'";
}
于 2013-07-30T22:41:32.300 回答