Welcome Guest, Not a member yet? Register   Sign In
Translate MySQL into active record, how?
#1

[eluser]überfuzz[/eluser]
I'm trying to translate MySQL into codeigniters active record. When I'm running a active record query I'm not getting the same result as I'm getting running it as an ordinary sql-query. This i the method I'm tinkering with, it's in a model.php.
Code:
function get_news()
    {
        
    $this->db->select('news.date AS date', 'news_events.event AS event');
    $this->db->from('news');
    $this->db->join('news_events', 'news_events.ID_news = news.ID');
    $this->db->where('active', 1);
    $query = $this->db->get();
        
        if ($query->num_rows() > 0)
        {
            return $query->result();
        }
    }

The Mysql looks like this:
Code:
SELECT news.date AS date, news_events.event AS event FROM news
JOIN news_events ON news_events.ID_news = news.ID
WHERE active = 1

The result in phpMyAdmin:
Code:
date     event
Aug 25     Mastring
Aug 25     20:00
Aug 25     Ministeriet mastrar sex glödheta låtar.
Sep 10     Test
Sep 10     Lorem ipsum dolor sit amet, consectetur adipisicin...

Result with active record. (It's fetched by a controller and passed to view. Nothing is done to the info in the controller and just test printed with print_r in viewer.):
Code:
date
Aug 25
Aug 25
Aug 25
Sep 10
Sep 10

Could anyone help me and point out what I'm doing wrong here?
#2

[eluser]überfuzz[/eluser]
Well, if I'd read the manual more closely I would have noticed that the select() function only takes one string. I changed my query like this:
Code:
FROM
        $this->db->select('news.date AS date', 'news_events.event AS event');

TO

        $this->db->select('news.date AS date');
        $this->db->select('news_events.event AS event');

:red:




Theme © iAndrew 2016 - Forum software by © MyBB