Jump to content

winco7

New Members
  • Posts

    4
  • Joined

  • Last visited

winco7's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. got it working now: while ($row = mysql_fetch_array($db_result)) { $userID = $row['user_id']; #users $bookID = $row['title']; #bookTitle $rating = $row['rating']; $ArraY[$userID][$bookID] = $rating; } thanks for your help
  2. Thank you very much. that really helped unto a certain point. I've been able to achieve this: Array ( [11] => Array ( [123715] => 5 [140329] => 5 [3083854] => 4 [871236761] => 1 [451179757] => 1 [451403886] => 3 ) [24] => Array ( [123715] => 5 [140329] => 5 [3083854] => 4 [871236761] => 1 [451179757] => 1 [451403886] => 3 [044661095X] => 4 [014010268X] => 1 [812576063] => 5 [038076654X] => 1 ) [12] => Array ( [123715] => 5 [140329] => 5 [3083854] => 4 [871236761] => 1 [451179757] => 1 [451403886] => 3 [044661095X] => 4 [014010268X] => 1 [812576063] => 5 [038076654X] => 1 [4428] => 5 [435477] => 5 [4489] => 2 [843945249] => 5 [743524772] => 1 ) [30] => Array ( [123715] => 5 [140329] => 5 [3083854] => 4 [871236761] => 1 [451179757] => 1 [451403886] => 3 [044661095X] => 4 [014010268X] => 1 [812576063] => 5 [038076654X] => 1 [4428] => 5 [435477] => 5 [4489] => 2 [843945249] => 5 [743524772] => 1 [078601556X] => 1 [1418413933] => 3 [786930616] => 5 [553159232] => 1 [8441406243] => 5 ) ) whereby for each user it shows a number of books and their rating, however at the moment those books are repeated and increase n times. instead of have each user's books and ratings separate from others. this is how i'm doing it: $one=array(); while ($row = mysql_fetch_array($db_result)) { $two = $row['user_id']; $one = $row['bookId']; $three[$one] = $row['rating']; unset($row['bookId']); unset($row['user_id']); $ArraY[$two] = $three; } print_r($ArraY); thanks for your continued assistance
  3. thank you so much getting there gradually. what I am aiming at really is : for each user, get the book, rating and put in different arrays like this: 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 ) ) Thanks
  4. 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.