Using array keys and values to create sql select statement

后端 未结 2 1462
轻奢々
轻奢々 2020-12-20 06:20

I am trying to pass a array that contains keys and values.

The keys are columns and values are the values to select.

I am trying to write a function where I

2条回答
  •  青春惊慌失措
    2020-12-20 06:52

    Use a foreach loop to iterate over the array and get key and value. Like this:

    $sql='';
    foreach($array as $key=>$value){
        $sql = sprintf("select * from table where %s = %s",$key,$value);
        print $sql;
    }
    

提交回复
热议问题