mysql output into php arrary -
mysql output into php arrary -
i's trying transform info mysql $books below doenst seem working
$books = array( "phil" => array("my girl" => 2.5, "the god delusion" => 3.5, "tweak" => 3, "the shack" => 4, "the birds in life" => 2.5, "new moon" => 3.5) ) this how tried doing:
$sql = "select * rating user_id=11 limit 5"; $db_result = mysql_db_query($dbname,$sql) or trigger_error(mysql_error()); $num_rows = mysql_num_rows($db_result) or trigger_error(mysql_error()); while ($row = mysql_fetch_array($db_result)) { $one = $row['bookid']; $two = $row['user_id']; $three = $row['rating']; $array= array( $two => array($one=>$three) ); print_r($array); } but :
array ( [11] => array ( [123715] => 5 ) ) array ( [11] => array ( [140329] => 5 ) ) array ( [11] => array ( [3083854] => 4 ) ) array ( [11] => array ( [871236761] => 1 ) ) array ( [11] => array ( [451179757] => 1 ) ) array ( [11] => array ( [451403886] => 3 ) ) array ( [24] => array ( [044661095x] => 4 ) ) array ( [24] => array ( [014010268x] => 1 ) ) array ( [24] => array ( [812576063] => 5 ) ) array ( [24] => array ( [038076654x] => 1 ) ) instead of like: array ( [phil] => array ( [my girl] => 2.5 [the god delusion] => 3.5 [tweak] => 3 [the shack] => 4 [the birds in life] => 2.5 [new moon] => 3.5 ) [sameer] => array ( [the lastly lecture] => 2.5 [the god delusion] => 3.5 [the noble wilds] => 3 [the shack] => 3.5 [the birds in life] => 2.5 [new moon] => 1 ) [john] => array ( [a one thousand splendid suns] => 5 [the secret] => 3.5 [tweak] => 1 ) [peter] => array ( [chaos] => 5 [php in action] => 3.5 ) [jill] => array ( [the lastly lecture] => 1.5 [the secret] => 2.5 [the noble wilds] => 4 [the host: novel] => 3.5 [the world without end] => 2.5 [new moon] => 3.5 ) [bruce] => array ( [the lastly lecture] => 3 [the hollow] => 1.5 [the noble wilds] => 3 [the shack] => 3.5 [the appeal] => 2 [new moon] => 3 ) [tom] => array ( [chaos] => 2.5 ) ) any help how can transform much appreciated
php mysql
Comments
Post a Comment