简体   繁体   English

杂货杂货店-无法区分返回查询表中的属性

[英]Grocery Crud - Can't differentiate attribute in returning query table

I've been using Grocery Crud to develop a simple local application that allows users to register themselves and like bands and rate them and select people they know that are also registered in the application. 我一直在使用Grocery Crud开发一个简单的本地应用程序,该应用程序允许用户注册自己和喜欢的乐队并对其进行评分,并选择他们认识的也在该应用程序中注册的人。

Entities: 实体:
Person(person_id,person_URL, fullname, hometown) 人(person_id,person_URL,全名,家乡)
Band(band_id,band_URL,band_name,country,genre) 乐队(band_id,band_URL,band_name,国家,流派)

Relationships: 关系:
Likes(person_id,band_id,rate) 喜欢(为person_id,band_id,速率)
Knows(person_id,known_person_id) 知道(为person_id,known_person_id)

My questions are: 我的问题是:

1) I want to return a table of person and known person like below: 1)我想返回一个人和已知人物的表格,如下所示:

KNOWS person_id | fullname | known_person_id | known_fullname

but I can't use *set_relation_n_n* function 'cause the relationship is (Person -> Likes -> Person), so it's giving me error. 但是我不能使用* set_relation_n_n *函数,因为这种关系是(Person-> Likes-> Person),所以它给了我错误。 The other solution I came up with is making a custom table making a query to return the values I want and show it in the table (code below). 我想到的另一种解决方案是制作一个自定义表,进行查询以返回我想要的值并将其显示在表中(下面的代码)。 The custom table returned is correct but when I render it to my Grocery Crud table, I need to specify $crud->columns('person_id', 'fullname', 'known_person_id', 'fullname'), and it cannot differentiate the fullname of the person and the fullname of the known person. 返回的自定义表是正确的,但是当我将其呈现到Grocery Crud表时,我需要指定$ crud-> columns('person_id','fullname','known_person_id','fullname'),并且不能区分全名人的姓名和已知人的全名。 How would I make it in order to be able to show the table that way? 我将如何制作才能以这种方式显示表格?

2) I have the same issue in another table but could manage that using the function *set_relation_n_n* 'cause it's a relationship (Person -> Likes -> Band), so since it's 2 different entities it didn't return me a error. 2)我在另一个表中也有同样的问题,但是可以使用功能* set_relation_n_n *来解决,因为这是一种关系(人->点赞->乐队),所以因为它是2个不同的实体,所以没有向我返回错误。 The problem is that the query (code below) returns me the whole table and I want only 25 records per page. 问题是查询(下面的代码)向我返回整个表,而我只希望每页25条记录。 When I try to use "LIMIT 25" in the query, it returns me ONLY 25 records and the "next page" button doesn't work. 当我尝试在查询中使用“ LIMIT 25”时,它仅返回25条记录,而“下一页”按钮不起作用。 Any solutions? 有什么办法吗?

Below, all the information: 以下是所有信息:

CODE for question 1: 问题1的代码:

function knows_management()
    {
    $crud = new grocery_CRUD();
    $crud->set_model('model_socialnetwork');
    $crud->set_table('knows');
    $crud->set_subject('Known');
    $crud->basic_model->set_query_str('SELECT tb1.person_id, tb1.fullname, tb1.known_person_id, person.fullname FROM (SELECT person.person_id, person.fullname, knows.known_person_id FROM person INNER JOIN knows ON person.person_id = knows.person_id) tb1 INNER JOIN person ON tb1.known_person_id = person.person_id');<br>
    $crud->columns('person_id','fullname','known_person_id','fullname');
    $output = $crud->render();
    $this->_socialnetwork_output($output);
    }

CODE for question 2: 问题2的代码:

function likes_management()
    {
        $crud = new grocery_CRUD();
        $crud->set_model('model_socialnetwork');
        $crud->set_table('likes');
        $crud->set_subject('Like');
        $crud->columns('person_id','fullname','band_id','band_name', 'rate');
        $crud->basic_model->set_query_str('SELECT tb2.person_id, tb2.fullname, tb2.band_id, band.band_name, tb2.rate FROM(SELECT tb1.person_id, person.fullname, tb1.band_id, tb1.rate FROM(SELECT person.person_id, likes.band_id, likes.rate FROM person INNER JOIN likes ON person.person_id = likes.person_id) tb1 INNER JOIN person ON tb1.person_id = person.person_id) tb2 INNER JOIN band ON tb2.band_id = band.band_id');
        $output = $crud->render();
        $this->_socialnetwork_output($output);
    }

Question 1) What if you use an alias name in your query, for example 问题1)例如,如果您在查询中使用别名,该怎么办

SELECT tb1.person_id, tb1.fullname as Tb1fullName, tb1.known_person_id, person.fullname as PersonFullName 选择tb1.person_id,tb1.fullname作为Tb1fullName,tb1.known_person_id,person.fullname作为PersonFullName

Question 2) I would not recommend you to add LIMIT directly / manually in your query. 问题2)我不建议您在查询中直接/手动添加LIMIT。 In the file application/config/grocery_crud.php, you have two options directly related to pagination 在文件application / config / grocery_crud.php中,您有两个与分页直接相关的选项

You should use and configure them properly 您应该正确使用和配置它们

// The default per page when a user firstly see a list page
$config['grocery_crud_default_per_page']    = 25;

....

    //Having some options at the list paging. This is the default one that all the websites are using.
    //Make sure that the number of grocery_crud_default_per_page variable is included to this array.
    $config['grocery_crud_paging_options'] = array('10','25','50','100');

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

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