2013-02-12 129 views
0

我使用查询像这样得到导师和研究机构。过滤查询结果

SELECT 
    t.tutor_id member_id, 
    t.tutor_name member_name, 
    t.tutor_code member_code, 
    'tutor' AS TYPE 
FROM 
    tutors t 
WHERE t.tutor_name LIKE '%jaya%' 
UNION 
SELECT 
    t.institute_id, 
    t.institute_name, 
    t.institute_code, 
    'institute' AS TYPE 
FROM 
    institute i 
WHERE i.institute_name LIKE '%jaya%' 

该查询根据给定关键字返回记录(导师和研究机构)。它为我工作。我的问题是我需要单独保存记录,因为导师和研究机构从查询中选择所有记录。我在页面上使用了名为'tutors'和'institute'的2个按钮来过滤查询结果。所以现在我需要知道我需要使用2级不同的查询为每个按钮或者如果不是我可以使用单个查询做到这一点的?

任何意见都大大升值。 谢谢。

+3

使用单独查询更简单,更高效 – 2013-02-12 07:26:13

+0

共享'tutors'和'institute'表的表格模式。 – SparKot 2013-02-12 07:26:26

+0

你能告诉我我如何共享表模式? – TNK 2013-02-12 07:30:11

回答

0

当一个按钮让假设导师点击发送两个指标的影响,以PHP函数

function searchTutors($type , $keyword) 
{ 
    if($type == 'tutors') 
    { 
     //tutors query here 
    }else{ 
     //institutions query here 
    } 
    return $your_query_result; 
} 
0

如果您希望只运行一个查询,你可以有不同的看法。

$type=$_POST['submit']; 

if($type=='tutor') 
{ 
    // show only columns from tutor table 
} 
else 
{ 
// show only columns from institute table 
}