php - Build SQL Select a better way ? (Oracle) -


i have following code part in 1 of classes:

                $l = new location();                 $result = $l->getlocidsbycity($city); // returns csv                 $ids = explode(',', $result);                  $where = 'loc_id = ' . $ids[0];                 unset($ids[0]);                  foreach ($ids $id) {                     $where .= ' or loc_id = ' . $id;                 }                  $select->where($where); 

is there more "elegant" way build select stmt? need records 1 of provided ids..

assuming csv injection safe (contains trusted values , no user-provided input):

            $l = new location();             $result = $l->getlocidsbycity($city); // returns csv             $where = "loc_id in ($result)";             $select->where($where); 

if it's not, should explode it, mysql_real_escape_string each value , implode back.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -