Welcome Guest, Not a member yet? Register   Sign In
Show null when data does not exist in database
#6

[eluser]Tim Brownlaw[/eluser]
I took your code - created a test controller - made up dummies of your two tables and tested the generated SQL... using echo $this->db->last_query();

So after tinkering with it I came up with this...


Code:
$this->db->from('ads as a');// I use aliasing make things joins easier
$this->db->join('membership as c', 'c.membership_id = a.ad_id', 'INNER');
$this->db->where('a.ad_id = c.ad_fk');
$q = $this->db->get();
Which creates
Code:
SELECT * FROM (`ads` as a) INNER JOIN `membership` as c ON `c`.`membership_id` = `a`.`ad_id` WHERE `a`.`ad_id` = c.ad_fk

What you have is generating this...
Code:
SELECT * FROM (`ads` AS A, `ads`) INNER JOIN `membership` AS C ON `C`.`membership_id` = `A`.`ad_id` WHERE `A`.`ad_id` = C.ad_fk
NOTE: I changed your membership.id to membership.membership_id so you can change that back to id.
Spot the difference! You are Selecting from (`ads` AS A, `ads`)

it always pays to examine what is actually being created and checking it!!!
With DB stuff - the ole echo $this->db->last_query() comes in very handy!



Messages In This Thread
Show null when data does not exist in database - by El Forum - 09-13-2014, 10:06 AM
Show null when data does not exist in database - by El Forum - 09-13-2014, 10:27 AM
Show null when data does not exist in database - by El Forum - 09-13-2014, 04:10 PM
Show null when data does not exist in database - by El Forum - 09-13-2014, 06:27 PM
Show null when data does not exist in database - by El Forum - 09-13-2014, 07:57 PM
Show null when data does not exist in database - by El Forum - 09-13-2014, 08:13 PM
Show null when data does not exist in database - by El Forum - 09-14-2014, 03:55 AM
Show null when data does not exist in database - by El Forum - 09-14-2014, 02:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB