visken Posted June 15, 2006 Share Posted June 15, 2006 Hi all,I am new to PHP and need your help with the following:I want to construct the following array named [b]$arr_user_movie[/b]: (n is number of user and m is number of movies)array ([1]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1array ([2]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1......array ([n]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1[b]example of use[/b]: $arr_user_movie[6][86] has to contain a 1 if user 6 has watched movie with id86, 0 otherwiseI made the following script, however at the end when I check the value PHP doesn't return anything! When I insert 'echo $arr_user_movie[6][86] before line 'for ($user_id=1; $user_id<=NUMBERUSERS; $user_id++)', then PHP returns 1.Can you help me?arr_movie=array(1=>1);for ($j=2; $j<=NUMBERMOVIES; $j++){$arr_movie[]=1;//zo voeg je telkens een veld toe}$i=1;$arr_user_movie=array($i=>$arr_movie);for($i=2; $i<=NUMBERUSERS; $i++){$arr_user_movie[]=$arr_movie;}// $arr_user_movie[x][x] bevat een waarde 1for ($user_id=1; $user_id<=NUMBERUSERS; $user_id++){ for ($movie_id=1; $movie_id<=NUMBERMOVIES; $movie_id++) { $query_user_movie="select * from rating where user_id=".$user_id." and movie_id=".$movie_id.""; $result_user_movie=mysql_query($query_user_movie, $connect); $num_results_user_movie=mysql_num_rows($result_user_movie); // if an entry found then set 1 else set 0: if ($num_results_user_movie==0) { $arr_user_movie[$user_id][$movie_id]=1; } else { $arr_user_movie[$user_id][$movie_id]=0; } }}[b]echo $arr_user_movie[1][1];[/b] Link to comment https://forums.phpfreaks.com/topic/12061-php-script-not-working/ Share on other sites More sharing options...
visken Posted June 15, 2006 Author Share Posted June 15, 2006 Hi maybe I have explained my problem not well. Therefore my first problem:How do you create the following array?(n is number of user and m is number of movies)[code]array ([1]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1array ([2]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1......array ([n]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1[/code]Thank you for your help!!![!--quoteo(post=384141:date=Jun 15 2006, 01:57 PM:name=visken)--][div class=\'quotetop\']QUOTE(visken @ Jun 15 2006, 01:57 PM) [snapback]384141[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi all,I am new to PHP and need your help with the following:I want to construct the following array named [b]$arr_user_movie[/b]: (n is number of user and m is number of movies)array ([1]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1array ([2]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1......array ([n]=>array([1]=>0/1 [2]=>0/1 [3]=>0/1 ... [m]=>0/1[b]example of use[/b]: $arr_user_movie[6][86] has to contain a 1 if user 6 has watched movie with id86, 0 otherwiseI made the following script, however at the end when I check the value PHP doesn't return anything! When I insert 'echo $arr_user_movie[6][86] before line 'for ($user_id=1; $user_id<=NUMBERUSERS; $user_id++)', then PHP returns 1.Can you help me?arr_movie=array(1=>1);for ($j=2; $j<=NUMBERMOVIES; $j++){$arr_movie[]=1;//zo voeg je telkens een veld toe}$i=1;$arr_user_movie=array($i=>$arr_movie);for($i=2; $i<=NUMBERUSERS; $i++){$arr_user_movie[]=$arr_movie;}// $arr_user_movie[x][x] bevat een waarde 1for ($user_id=1; $user_id<=NUMBERUSERS; $user_id++){ for ($movie_id=1; $movie_id<=NUMBERMOVIES; $movie_id++) { $query_user_movie="select * from rating where user_id=".$user_id." and movie_id=".$movie_id.""; $result_user_movie=mysql_query($query_user_movie, $connect); $num_results_user_movie=mysql_num_rows($result_user_movie); // if an entry found then set 1 else set 0: if ($num_results_user_movie==0) { $arr_user_movie[$user_id][$movie_id]=1; } else { $arr_user_movie[$user_id][$movie_id]=0; } }}[b]echo $arr_user_movie[1][1];[/b][/quote] Link to comment https://forums.phpfreaks.com/topic/12061-php-script-not-working/#findComment-45873 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.