简体   繁体   English

codeigniter活动记录和mysql

[英]codeigniter active record and mysql

I am running a query with Active Record in a modal of my codeigniter application, the query looks like this, 我在我的codeigniter应用程序的模式中运行Active Record查询,查询如下所示,

public function selectAllJobs()
{
    $this->db->select('*')
             ->from('job_listing')
             ->join('job_listing_has_employer_details', 'job_listing_has_employer_details.employer_details_id = job_listing.id', 'left');
             //->join('employer_details', 'employer_details.users_id = job_listing_has_employer_details.employer_details_id');

    $query = $this->db->get();
    return $query->result_array();
}

This returns an array that looks like this, 这将返回一个如下所示的数组,

    [0]=>
  array(13) {
    ["id"]=>
    string(1) "1"
    ["job_titles_id"]=>
    string(1) "1"
    ["location"]=>
    string(12) "Huddersfield"
    ["location_postcode"]=>
    string(7) "HD3 4AG"
    ["basic_salary"]=>
    string(19) "£20,000 - £25,000"
    ["bonus"]=>
    string(12) "php, html, j"
    ["benefits"]=>
    string(11) "Compnay Car"
    ["key_skills"]=>
    string(1) "1"
    ["retrain_position"]=>
    string(3) "YES"
    ["summary"]=>
    string(73) "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
    ["description"]=>
    string(73) "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
    ["job_listing_id"]=>
    NULL
    ["employer_details_id"]=>
    NULL
  }
}

The job_listing_id and employer_details_id return as NULL however if I run the SQL in phpmyadmin I get full set of results, the query i running in phpmyadmin is, job_listing_id和employer_details_id返回NULL但是如果我在phpmyadmin中运行SQL我得到完整的结果集,我在phpmyadmin中运行的查询是,

    SELECT *
FROM (
`job_listing`
)
LEFT JOIN `job_listing_has_employer_details` ON `job_listing_has_employer_details`.`employer_details_id`
LIMIT 0 , 30

Is there a reason why I am getting differing results? 我有没有理由得到不同的结果?

Run the $this->db->last_query() and check the difference. 运行$ this-> db-> last_query()并检查差异。 It's a very useful debugging tool. 这是一个非常有用的调试工具。

Of course the limit will have an effect, but I'm ignoring that. 当然限制会产生影响,但我忽略了这一点。

It seems in your query in phpmyadmin, your 'ON' doesn't have a second part. 在phpmyadmin的查询中,您的“ON”没有第二部分。 I think your query in phpmyadmin should be: 我认为你在phpmyadmin中的查询应该是:

SELECT *
FROM (
`job_listing`
)
LEFT JOIN `job_listing_has_employer_details` ON `job_listing_has_employer_details`.`employer_details_id` =  = `job_listing`.`id`

You should be using result_array, despite what the other person said. 你应该使用result_array,尽管对方说的是什么。

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

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