用PHP if语句查询mysql?

时间:2013-01-14 08:31:55

标签: php mysql if-statement

$country$job_type值来自下拉列表

if ($country == 'All' && $job_type == 'All') {
    $data = mysql_query("SELECT * FROM cv ")
}else {
    $data = mysql_query("SELECT * FROM cv WHERE country='$country' AND job='$job_type'")      
}

1 个答案:

答案 0 :(得分:4)

你似乎错过了一些;,试试这个:

if ($country == 'All' && $job_type == 'All') 
{
  $data = mysql_query("SELECT * FROM cv WHERE country='$country' AND job='$job_type'");
} else {
  $data = mysql_query("SELECT * FROM cv");
}

本杰明有一点意见,你的IF逻辑似乎不对。也许你想要这个?

if ($country == 'All' && $job_type == 'All') 
{
  $data = mysql_query("SELECT * FROM cv");
} else {
  $data = mysql_query("SELECT * FROM cv WHERE country='$country' AND job='$job_type'");
}