如何对我的代码进行一次查询

时间:2017-04-10 06:08:40

标签: php mysql codeigniter

如何对我的代码进行一次查询

$sql = "SELECT id FROM countries WHERE country_code = LEFT($number,3)"; 
$sql = "SELECT id FROM countries WHERE country_code = LEFT($number,2)"; 
$sql = "SELECT id FROM countries WHERE country_code = LEFT($number,1)"; 
$sql = "SELECT id FROM countries WHERE country_code = 0";

3 个答案:

答案 0 :(得分:1)

$sql = "SELECT id
FROM countries
WHERE country_code = LEFT($number,3)
  OR country_code = LEFT($number,2)
  OR country_code = LEFT($number,1)
  OR country_code = 0"; 

答案 1 :(得分:1)

如果你想要严格的话,根据你的情况,如果没有,则使用AND,然后OR

$sql = "SELECT id FROM countries WHERE country_code = LEFT($number,3) OR 
        country_code = LEFT($number,2) OR country_code = LEFT($number,1) OR 
        country_code =0 "; 

答案 2 :(得分:1)

// ...
std::string word;
std::vector<std::string> words;

while ( codeFile >> word )
{
    if ( word.empty() ) continue;
    std::cout << word << '\n';
    words.push_back(std::move(word));
}