我发现当内部存在相同的变量时,只读取了第一个if条件,并且如果条件,则跳过另一个其他条件。怎么解决?
<select name='selectcriteria' class="form-control" multiple>
<option value="education">Education</option>
<option value="orphan">Orphan</option>
<option value="madrasah">Madrasah</option>
<option value="scholarship">Scholarship</option>
<option value="socialwalfare">Social Walfare</option>
</select>
If(isset($_GET['selectcriteria'])){
$criteria=$_GET['selectcriteria'];
if($criteria=='education'){
$sqlselect="SELECT * FROM criteria WHERE criteria ='education'";
}
else if($criteria=='madrasah'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'madrasah'";
}
else if($criteria=='orphan'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'orphan'";
}
else if($criteria=='scholarship'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'scholarship'";
}
else if($criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'socialwalfare'";
}
else if($criteria=='education'&&$criteria=='madrasah'){
$sqlselect="SELECT * FROM criteria WHERE criteria ='education' OR criteria = 'madrasah'";
}
else if($criteria=='education'&&$criteria=='orphan'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'education' OR criteria= 'orphan'";
}
else if($criteria=='education'&&$criteria=='scholarship'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'education' OR criteria = 'scholarship'";
}
else if($criteria=='education'&&$criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'education' OR criteria = 'socialwalfare'";
}
else if($criteria=='education'&&$criteria=='madrasah'&&$criteria=='orphan'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'education' OR criteria = 'madrasah' OR criteria = 'orphan'";
}
else if($criteria=='education'&&$criteria=='madrasah'&&$criteria=='scholarship'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'education' OR criteria = 'madrasah' OR criteria = 'scholarship'";
}
else if($criteria=='education'&&$criteria=='madrasah'&&$criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'education' OR criteria = 'madrasah' OR criteria = 'socialwalfare'";
}
else if($criteria=='education'&&$criteria=='madrasah'&&$criteria=='socialwalfare'&&$criteria=='orphan'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'education' OR criteria = 'madrasah' OR criteria = 'socialwalfare' OR criteria= 'orphan'";
}
else if($criteria=='madrasah'&&$criteria=='orphan'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'madrasah' OR criteria = 'orphan'";
}
else if($criteria=='madrasah'&&$criteria=='scholarship'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'madrasah' OR criteria = 'scholarship'";
}
else if($criteria=='madrasah'&&$criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'madrasah' OR citeria = 'socialwalfare'";
}
else if($criteria=='madrasah'&&$criteria=='orphan'&&$criteria=='scholarship'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'madrasah' OR criteria = 'orphan' OR criteria = 'scholarship'";
}
else if($criteria=='madrasah'&&$criteria=='orphan'&&$criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'madrasah' OR criteria = 'orphan' OR criteria ='socialwalfare'";
}
else if($criteria=='madrasah'&&$criteria=='scholarship'&&$criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'madrasah' OR criteria = 'scholarship' OR criteria='socialwalfare'";
}
else if($criteria=='orphan'&&$criteria=='scholarship'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'orphan' OR criteria = 'scholarship'";
}
else if($criteria=='orphan'&&$criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'orphan' or criteria = 'socialwalfare'";
}
else if($criteria=='orphan'&&$criteria=='scholarship'&&$criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'orphan' OR criteria = 'scholarship' OR criteria = 'socialwalfare'";
}
else if($criteria=='scholarship'&&$criteria=='socialwalfare'){
$sqlselect="SELECT * FROM criteria WHERE criteria = 'scholarship' OR criteria = 'socialwalfare'";
}
$resultselect = mysqli_query($conn, $sqlselect);
当它在while条件下显示时,只显示与任何第一个条件匹配的数据,而跳过其他值而不读取。例如,如果我多选教育和奖学金,网址中的变量应该带有selectcriteria = education&amp; selectcriteria = scholarship。但是随后会跳过一个值,因为另一个值与条件匹配。
答案 0 :(得分:1)
由于您将获得多个值,因为它是多选的,您可以像这样使用它:
IN
选项2:
我相信,你也可以使用$selected = $_GET['selectcriteria'];
$values = explode(',', $selected);
$joinValues implode("' ", $values);
$query = "SELECT * FROM criteria WHERE criteria in ('" . $joinValues . "');
条款。
var your_stringify_obj=JSON.stringify(your_Multidimensional_Json).
$.ajax({
type: "GET",
url: 'url'+page.data.id,
dataType: "JSON",
data: your_stringify_obj,
timeout: 10000,
success: function(result){
$.each(result[0], function (index,el) {
$('#prosesloadingharga').hide();
console.log("harga paket : " +el.harga+" , id harga paket : "+el.id);
});
},
error: function(xhr, textStatus, thrownError) {
console.log("error",xhr.error);
}
});
};
答案 1 :(得分:1)
我不熟悉php的语法,但可以完成以下内容:
有一个字符串,上面写着=&#34;从标准中选择*,其中的条件为(&#34;
然后在&#39;中选择&#39;菜单,您可以使用它们附加到上面定义的字符串,最后正确关闭SQL字符串。
if(selectedvalue == abc){ 附加到字符串&#39; abc&#39; }
if(selectedvalue == xyz){ 附加到字符串,&#39; xyz&#39; }
最后附加&#39;)&#39;