Welcome Guest, Not a member yet? Register   Sign In
Require help with a couple LEFT JOIN's
#1

[eluser]kaisama[/eluser]
Hello all :x As I'm porting my current website over to using CodeIgniter, I have run into a small dilemma. Through all my tries, I cannot "translate" my original MySQL query call over to CI's method.

My Original Query:
Code:
$active_members_sql = "

SELECT akira_artists_bands.stage_name_romaji, akira_artists_bands.stage_name_kana, akira_artists_bands.position_id, akira_artists_positions.position

FROM akira_artists_bands

LEFT JOIN akira_artists_positions
ON akira_artists_bands.band_id=$band_id AND akira_artists_bands.position_id=akira_artists_positions.id

WHERE akira_artists_bands.band_id=$band_id AND
akira_artists_bands.status = 'Active' AND
akira_artists_bands.support = '0'

ORDER BY akira_artists_positions.sort ASC

";

I put the spaces in it to make it a little easier to read. How I love CI's clean code method of handling this @@;

I can do everything in CI except the LEFT JOINs.

Current CI Code:
Code:
$akira_db->from('akira_artists_bands');
$akira_db->join('akira_artists_positions', array('band_id' => $band_id), 'left');
$akira_db->join('akira_artists_positions', 'position_id = position_id', 'left');
$akira_db->where('band_id', $band_id);
$akira_db->where('status', $status);
$akira_db->where('solo_project', $solo);

I can get it to work without errors if I omit line 2 above (the first LEFT JOIN call), but of course, it doesn't pull the right data that I need.

I'm also not sure how to do my ORDER BY in CodeIgniter.

I hope I explained everything clearly. Any help on this would be awesome. It's driving me crazy.

Thanks in advance~


Messages In This Thread
Require help with a couple LEFT JOIN's - by El Forum - 09-12-2009, 08:57 PM
Require help with a couple LEFT JOIN's - by El Forum - 09-12-2009, 09:41 PM
Require help with a couple LEFT JOIN's - by El Forum - 09-13-2009, 09:48 AM
Require help with a couple LEFT JOIN's - by El Forum - 09-13-2009, 12:24 PM
Require help with a couple LEFT JOIN's - by El Forum - 09-13-2009, 01:47 PM
Require help with a couple LEFT JOIN's - by El Forum - 09-13-2009, 02:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB