在3个不同的查询之间进行选择,然后使用一个带结果的查询


Select between 3 different querys and use the one with results

大家好,

我想知道在3个不同的查询之间进行选择并使用有结果的查询的最佳方法。。。

    Select * from table where lugar in (1, 2, 3)

    Select * from table where lugar in (4, 5, 6)

    Select * from table where lugar in (7, 8, 9, 10)

我能用开关之类的东西吗?

我需要更多的想法来做…

我不使用"if",因为带有结果的查询必须使用大量代码。。。

提前感谢!

马里奥·马塔。

您可以像这样使用

$var_val="abc";
switch ($var_val)
{
  case "aa":
   $qry = "Select * from table where lugar in (1, 2, 3)";
   break;
 case "abc":
   $qry = "Select * from table where lugar in (4, 5, 6)";
   break;
 case "cc":
   $qry = "Select * from table where lugar in (7, 8, 9,10)";
   break;
 default:
   $qry = "Select * from table";
}

我认为你真的必须使用if语句,它最适合你的问题

$query = mysql_query('Select * from table where lugar in (1, 2, 3)');
if(mysql_num_rows($query)){
//this will check if there was a result on a given query
}

只是循环来实现另一个。。好日子

您可以设置一个数组变量。然后更改交换机中阵列的内容,而不是SELECT statement

switch($something) {
    case 'a':
        $in = array(1,2,3);            
        break;
    case 'b':
        $in = array(4,5,6);            
        break;
    case 'c':
        $in = array(7,8,9,10);            
        break;
    default:
        $in = array(1,2,3);
}
SELECT * FROM table WHERE lugar IN ($in)