php - How can I extract values from an array into a variable? -
i'm using next code print array:
//sql query $query = "select wp_arf_entry_values.entry_value, wp_arf_entry_values.id wp_arf_entry_values entry_id=1"; //execute sql query , homecoming records $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ $results[] = $row; } //print array in human readable form print("<pre>".print_r($results,true)."</pre>");
this output:
array ( [0] => array ( [entry_value] => john [id] => 1 ) [1] => array ( [entry_value] => doe [id] => 2 ) [2] => array ( [entry_value] => 19 [id] => 3 ) [3] => array ( [entry_value] => male [id] => 4 ) )
i'm having hard time figure out how can extract array's values variables, (not actual code, example):
$fname = 'entry_value' has id = 1 $lname = 'entry_value' has id = 2 $age = 'entry_value' has id = 3 $genre = 'entry_value' has id = 4
i've researched here past hr can't find reply helps me. what's feasible way this?
assumption:id values unique in db
change code to
$results = array(); while($row = mysql_fetch_assoc($result)){ $results[$row['id']] = $row['entry_value']; } //print array in human readable form print("<pre>".print_r($results,true)."</pre>");
and can have values as:
$fname = $results['1'] $lname = $results['2'] $age = $results['3'] $genre = $results['4']
php
No comments:
Post a Comment