Friday, 15 August 2014

mysql - Left Join Drupal 7 -



mysql - Left Join Drupal 7 -

i have problem regarding drupal 7 mysql queries on left join.

i found solution can't seem apply on problem since i'm not aware how syntax goes.

http://drupal.stackexchange.com/questions/4317/how-do-i-write-a-left-join-query

this solution found on link above.

$terms = db_select('taxonomy_index', 'ti') ->fields('ti', array('tid', 'name')) ->leftjoin('taxonomy_term_data', 'ttd', 'ti.tid = ttd.tid') ->condition('vid', 2) ->condition('nid', $nid) ->execute(); foreach ($terms $term) { // $term contains object taxonomy term. }

yet i'm having problem on how apply query.

here left bring together query on mysql.

$query = "select sweep_table.end_offer, sweep_table.title, embed.fbp_id, embed.sweep_stat sweep_table, embed sweep_table.uid=embed.uid , sweep_table.promo_id=embed.sweep_id";

i did first few lines rest, don't know how.

$terms = db_select('sweep_table', 'embed') ->fields('sweep_table', array('end_offer', 'title')) ->fields('embed', array('fbp_id', 'sweep_stat')) ->leftjoin('taxonomy_term_data', 'ttd', 'ti.tid = ttd.tid') //don't know how apply query. ->condition('vid', 2) ->condition('nid', $nid) ->execute(); foreach ($terms $term) { }

also, wondering how retrieve info after left bring together it?

would glad if help me guys.

wouldn't have thought work though. rekire hint.

$query = "select sweep_table.end_offer, sweep_table.title, embed.fbp_id, embed.sweep_stat sweep_table, embed sweep_table.uid=embed.uid , sweep_table.promo_id=embed.sweep_id"; $result = db_query($query); foreach ($result $row) { echo $row->end_offer . " " . $row->title . " " . $row->fbp_id . " " . $row->sweep_stat . "<br>"; }

mysql drupal-7 left-join

No comments:

Post a Comment