Create SQL OR ID List


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.