我有一种情况需要比较同一个表的3个不同的选择选项字段。我比较了3个字段,2个字段和1个字段。显示相应的结果,但在一个字段条件(category
)中不显示结果。
<?php
include'connect.php';
if(isset($_POST['submit']))
{
$qn=$_POST['location'];//LOCATION
$qn1=$_POST['category'];//CATEGORY
$qn2=$_POST['salary'];//SALARY
if(isset($_POST['location']))
{
$q2=mysql_query("SELECT * FROM job_posting where location='$qn'");
while($quew=mysql_fetch_array($q2))
{
echo $ans=$quew['title'];
}
}
else
{
$qir=mysql_query("SELECT * FROM job_posting where category='$qn1'");
while($quew=mysql_fetch_array($qir))
{
echo $gn=$quew['title'];
}
}
if(isset($_POST['location']) && isset($_POST['category']))
{
$q3=mysql_query("SELECT * FROM job_posting where location='$qn' && category='$qn1'");
while($quew=mysql_fetch_array($q3))
{
echo $ans2=$quew['title'];
}
}
if(isset($_POST['location']) && isset($_POST['category']) && isset($_POST['salary']))
{
$q4=mysql_query("SELECT * FROM job_posting where location='$qn' && category='$qn1' && minsalary='$qn2'");
while($quew=mysql_fetch_array($q4))
{
echo $ans3=$quew['title'];
}
}
if(isset($_POST['location']) || isset($_POST['category']) && isset($_POST['salary']))
{
$q5=mysql_query("SELECT * FROM job_posting where location='$qn' || category='$qn1' && minsalary='$qn2'");
while($quew=mysql_fetch_array($q5))
{
echo $ans4=$quew['title'];
}
}
if(isset($_POST['location']) && isset($_POST['category']) || isset($_POST['salary']))
{
$q7=mysql_query("SELECT * FROM job_posting where location='$qn' && category='$qn1' || minsalary='$qn2'");
while($quew=mysql_fetch_array($q7))
{
echo $ans5=$quew['title'];
}
}
}
?>
答案 0 :(得分:0)
首先,我可以想到三件事
数据库查询=&gt;检查是否请求“类别”
数据库类型=&gt; utf8-bin,utf8-general-ci等。因为如何保存数据非常重要。
服务器文件“php.ini”=&gt;检查“default_charset”和“mbstring ...”参数,对管理字符串类型数据很重要。
如果您需要更多帮助,只需发送更多信息
答案 1 :(得分:-1)
试试这个:
if (!empty($_POST['location'])) {
$lq = "&& location='$_POST['location']'";
}
if (!empty($_POST['category'])) {
$cq = "&& category='$_POST[category]'";
}
if (!empty($_POST['salary'])) {
$sq = "&& minsalary='$_POST[salary]'";
}
$qr = mysql_query("SELECT * FROM job_posting WHERE 1 $lq $cq $sq");
while ($rs = mysql_fetch_array($qr)) {
// do whatever you want
}