简体   繁体   English

过滤查询结果

[英]filtering query result

I use a query something like this to get tutors and institutes. 我使用类似这样的查询来获取导师和学院。

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%' 

This query is returning both records (tutors and institutes) according to given keyword. 该查询根据给定的关键字返回两个记录(教师和学院)。 Its working for me. 它为我工作。 My problem is I need to keep record separately as tutors and institutes afters selecting all records from the query. 我的问题是,从查询中选择所有记录后,我需要分别保存教师和机构的记录。 I have use 2 buttons named 'tutors' and 'institute' on my page to filter query result. 我在页面上使用了两个名为“ tutors”和“ institute”的按钮来过滤查询结果。 So now I need to know do I need to use 2 different queries for each button or if not can I use single query for do this? 因此,现在我需要知道是否需要对每个按钮使用2个不同的查询,或者如果不能,我可以使用单个查询吗?

Any comments are greatly appreciating. 任何评论都非常感谢。 Thank you. 谢谢。

When a button let suppose tutors is clicked send two parametes to php function 当让老师单击按钮时,将两个参数发送给php函数

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

If you desire to run a single query only, you can have separate views. 如果只想运行一个查询,则可以有单独的视图。

$type=$_POST['submit'];

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM