Posted By

iloveitaly on 07/24/09


Tagged

database sql list db id or


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


Create SQL OR ID List


 / Published in: PHP
 

  1. function createIDList($idList, $dbFieldName) {
  2. if(count($idList) == 0) return '';
  3.  
  4. $orString = '';
  5.  
  6. foreach($idList as $id) {
  7. $orString .= "{$dbFieldName} = '{$id}' OR ";
  8. }
  9.  
  10. return substr($orString, 0, -4);
  11. }
  12.  
  13. // ex:
  14. $query = "SELECT * FROM table_name WHERE ".createIDList(array(array('id_field' => 1), array('id_field' => 2)));

Report this snippet  

You need to login to post a comment.