I have two different plugin tables and I want to get their value by sql. Problem is id where I cannot find connection which I can retrieve data.
postid = 2 and mapid = 3
mapid = 3 and obj = json
<? $postid = get_the_ID();
$results = $GLOBALS['wpdb']->get_results( 'SELECT obj FROM bdt_mappress_maps INNER JOIN bdt_mappress_posts WHERE bdt_mappress_maps.mapid = bdt_mappress_posts AND bdt_mappress_posts.postid ='.$postid); print_r($results);
?>
$postid returns me id of the post. The sql returns me empty value, I know sql but not so strong. If someone can help me or give related post which I can find answer. Thanks beforehand!
assuming that the two table are related by mapid for both of the tables you should use a join with on condition
$results = $GLOBALS['wpdb']->get_results( 'SELECT mapid
FROM bdt_mappress_maps
INNER JOIN bdt_mappress_posts
on (bdt_mappress_maps.mapid = bdt_mappress_posts
AND bdt_mappress_posts.id ='.$postid));
<? $postid = get_the_ID();
$results = $GLOBALS['wpdb']->get_results( 'SELECT obj FROM bdt_mappress_posts INNER JOIN bdt_mappress_maps WHERE bdt_mappress_posts.mapid = bdt_mappress_maps.mapid AND bdt_mappress_posts.postid ='.$postid); print_r($results);
?>
That should only changing the place the rule of the left sql