php - Select in MYSQL -- Select all the records -


i have function below:

public function select($id=null) {     $query = "select * press_releases id = {$id}";      $results = $this->db->query($query);      return $results; } 

if no $id specified during function invoke, want return records think null default value not option that. should instead of null retrieve records other using query doesn't specify id field in section.

thanks...

$query = "select * press_releases"; if (!empty($id)) {    $query .= "where id = {$id}"; } 

if $id integer, use:

$id = (int) $id; if ($id > 0) ... 

either way make sure $id safe use.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -