PHP在函数中添加多个JOIN方法

I have this function for fetch catid and typeid from MySQL database.

function _is_type_($id,$type){

    $db = mysqli_access::F("SELECT catid,typeid FROM " . CATSGROUP . " WHERE postid = ? AND typeid = ?", $id, $type);

    foreach($db as $row){
      $catsdata[] = $row;
    }
    return $catsdata;
} 

catsgroup table:(insert for each post catid and typeid)

|id|  catsid  |  typeid  |  postid  |

I have another two table for cats name and type name like this :

cats name table:

|id|cat_name|

type table:

|id|type_name|

Now In action I need to show/print name of catid and typeid from another table. I know, I can add PHP JOIN method in my function but I don't know how do can I?! How do generate my result (show name o cats and type) using JOIN method for my function?

Now

I don't think you will require join in this case as you need to fetch data from two different tables with two different keys. Also, I am assuming that id column in name and type table has no relation.

Here, writing to separate query can give you quicker result than going for join.

select cat_name from name where id=$id;
select type_name from type where id=$type;

This looks more like an SQL question. Also, as codeSun said there is no relation between the tables.

I suggest you read up on databases/sql.

Still, to answer your question, your query should go something like this:

$db = mysqli_access::F("S SELECT catid,typeid,{your join table}.type_name FROM " . CATSGROUP . " INNER JOIN {your join table} ON {your join table}.{pk} = " . CATSGROUP . ".{fk} WHERE postid = ? AND typeid = ?", $id, $type);

Please try this and give some feedback.

select a.catid,a.typeid,b.cat_name,c.type_name
from catsgroup a
inner join catsname b on b.id = a.catid
inner join type c on c.id = a.typeid
where a.postid = ''
and a.typeid = ''