Jump to content

inner join used in OOP


spires

Recommended Posts

Hi

 

I want to know I can select which ID I get from an inner join?

 

Not sure If I should post here or in the MYSQL forum, but as it's using OOP I posted here.

 

 

$sql = "SELECT * FROM area_county INNER JOIN area_country ";
$sql .= "ON area_county.country_id = area_country.id ";
$sql .= "ORDER BY area_country.country, area_county.county ASC ";
$sql .= "LIMIT {$per_page} ";
$sql .= "OFFSET {$pagination->offset()}";
$list = Area_county::find_by_sql($sql);

foreach($list as $lists){
$ID = $lists->id;
$country_id = $lists->country_id;
$county = ucwords($lists->county);
        $country = ucwords($lists->country);

echo $ID;
}

 

 

I want it to show the ID of the county, NOT the id of the country.

both tables in the database have the ID column called id.

 

I know this can be done, but not to sure how.

 

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/219286-inner-join-used-in-oop/
Share on other sites

Query need to be the other way around:

 

$sql = "SELECT * FROM area_country INNER JOIN area_county  ";
$sql .= "ON area_country.id = area_county.country_id ";
$sql .= "ORDER BY area_country.country, area_county.county ASC ";
$sql .= "LIMIT {$per_page} ";
$sql .= "OFFSET {$pagination->offset()}";
$list = Area_county::find_by_sql($sql);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.