Php 筛选查询结果

Php 筛选查询结果,php,mysql,Php,Mysql,我使用类似这样的查询来获取导师和研究所 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,

我使用类似这样的查询来获取导师和研究所

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%' 
此查询根据给定的关键字返回两个记录(导师和学院)。这对我有用。我的问题是,在从查询中选择所有记录后,我需要作为导师和研究所分别保存记录。我在页面上使用了两个名为“导师”和“研究所”的按钮来过滤查询结果。所以现在我需要知道我是否需要为每个按钮使用两个不同的查询,或者如果不是,我是否可以使用单个查询来执行此操作

任何评论都非常感谢。
多谢各位

单击“让假设导师”按钮时,向php函数发送两个参数

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

如果只希望运行单个查询,则可以使用单独的视图

$type=$_POST['submit'];

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

使用单独的查询更容易、更有效地为
导师
研究所
表共享表架构。您能告诉我如何共享表架构吗?为什么在
联合
之后要引用
导师
表?顺便说一句,可以使用
显示创建表
生成@TharangaNuwan表架构