I's trying to transform data from mysql into
something like $books below but it doenst seem to be working
$books = array(
"phil" => array("my girl" => 2.5, "the god delusion" => 3.5,
"tweak" => 3, "the shack" => 4,
"the birds in my life" => 2.5,
"new moon" => 3.5)
)
this is how I tried doing:
$sql = "SELECT * from rating where 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 this is what i get :
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 something like:
Array (
[phil] => Array (
[my girl] => 2.5
[the god delusion] => 3.5
[tweak] => 3
[the shack] => 4
[the birds in my life] => 2.5
[new moon] => 3.5
)
[sameer] => Array (
[the last lecture] => 2.5
[the god delusion] => 3.5
[the noble wilds] => 3
[the shack] => 3.5
[the birds in my life] => 2.5
[new moon] => 1
)
[john] => Array (
[a thousand splendid suns] => 5
[the secret] => 3.5
[tweak] => 1
)
[peter] => Array (
[chaos] => 5
=> 3.5 ) [jill] => Array ( [the last lecture] => 1.5 [the secret] => 2.5 [the noble wilds] => 4 [the host: a novel] => 3.5 [the world without end] => 2.5 [new moon] => 3.5 ) [bruce] => Array ( [the last 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 with how i can transform that will be much appreciated THANKS