简体   繁体   English

杂货店中的多项选择

[英]Multiple select in grocery crud

I have 3 tables in my db "employees", "sign", "subscription", and all of my tables has this same construct. 我的数据库中有3个表“ employees”,“ sign”,“ subscription”,并且我的所有表都具有相同的结构。

It is possible to view in one table all my records? 可以在一张表中查看我的所有记录吗?

public function index()
{
    $this->grocery_crud->set_table('employees');
    $output=$this->grocery_crud->render();

    $this->grocery_crud->set_table('sign');
    $output2=$this->grocery_crud->render();
    $this->_example_output($output2);
}

This generate 2 tables, but I want to put all records in one table. 这将生成2个表,但是我想将所有记录放在一个表中。

Sorry for my english. 对不起我的英语不好。 Thanks for help. 感谢帮助。

I'm a little confused because above your code you say "view in one table" but below you say "put in one table". 我有点困惑,因为在您的代码上方您说“在一个表中查看”,但在您下方说“输入一个表”。 I'll assume you want to "view" from the database, not "put" into the database. 我假设您要从数据库“查看”,而不是“放入”数据库。

If you have access to your SQL, you can get (for viewing) records from all 3 tables in a single SQL statement by using UNION ... 如果可以访问SQL,则可以使用UNION在单个SQL语句中从所有3个表中获取(供查看)记录。

SELECT col1, col2, col3 FROM EMPLOYEES
UNION
SELECT col1, col2, col3 FROM SIGN
UNION
SELECT col1, col2, col3 FROM SUBSCRIPTION

Note that this is 1 SQL statement (I've broken into multiple lines for readability). 请注意,这是1条SQL语句(为了便于阅读,我分为多行)。 The database will append the results and return all records to you in one query. 数据库将追加结果,并在一个查询中将所有记录返回给您。

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

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