php - string to array return array in parameter -


i string this, "voornaam, achternaam" give function.

when used string data database.

mysql_query("select."$string". ...")

this goes good.

now. want give values selected db.

i tried this.

<?php function user_info($user_id, $fetch = "") { if (ctype_digit($user_id)) {     if (empty($fetch))     {         $fetch = "*";     }     $query = mysql_query("select ".$fetch." accounts id = '".$user_id."'");     $data = mysql_fetch_assoc($query);     $data['password'] = null; }  if (empty($fetch)) {     return $data; } else {     $fetch = explode(", ", $fetch);     print_r($fetch);     while($param = $fetch) {         return $data[$param];     } }  //$item_result['created_by'] gives digit user_info($item_result['created_by'], 'voornaam, achternaam') 

im stuck in while loop.
not realy in loops.
tried , me seems logical.
in way wont work.

try change

  while($param = $fetch) {     return $data[$param]; } 

on foreach loop:

$temp = array(); foreach($featch $key){   $temp[$key] = (empty($data[$key]) ? ''  :  $data[$key] ); } return $temp; 

update

or can use loop :

$temp = array(); for( $i =0; $i < count($fetch); $i++){   $temp[$fetch[$i]] = (empty($data[$fetch[$i]]) ? ''  :  $data[$fetch[$i]] ); } return $temp; 

update 2

or while loop

$temp = array(); while(count($fetch)){   $key = array_shift($fetch);   $temp[$key] = (empty($data[$key]) ? ''  :  $data[$key] ); } return $temp; 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -