Sql – how to Join two table in php

# Join Two Table data in Sql using php

// used for select data
$join_sel = "p.id,p.approved,pc.cid";

//Use for select table & join
$join_frm = 'products as p JOIN product_cats as pc  ON p.id = pc.offer_id';

// Use for Where condition to select data
$join_cond = " WHERE p.id > 0 AND pc.cid = '12' AND p.approved = 'yes' GROUP BY p.id";

// Now the Sql Query look like:
$join_query_sql = "SELECT ".$join_sel." FROM ".$join_frm.$join_cond;

// Execute MySql Query
$join_query = mysql_query($join_query_sql);

// Found Joining Results Row 
$join_found_row = mysql_num_rows($join_query);

echo $join_found_row;
Please follow and like us: