0
나는 영화 테이블을 가지고 있고 두 명의 사용자의 공통 영화를 비교하고 싶습니다.PHP에서 두 개의 mysql 테이블을 비교하는 방법
$array1=array(); $array2=array(); $query2="select name from movie where user_id='2'"; $result2=mysql_query($query2) or die(mysql_error()); while($rss = mysql_fetch_assoc ($result2)) { $array1[]=$rss; } print_r($array1);
이
Array ([0] => Array ([name] => Snatch) [1] => Array ([name] => The Social Network Movie)
[2] => Array ([name] => Death Note) [3] => Array ([name] => Titanic)
[4] => Array ([name] => Once Upon a Time in the West))
를 인쇄합니다 그리고 난 그것이 나에게 첫 번째 배열을 제공 이러한 두 배열을 비교하면 두 번째 사용자
$query3="select name from movie where user_id=1"; $result3= mysql_query($query3) or die(mysql_error()); while($rss1= mysql_fetch_assoc($result3)) { $array2[]=$rss1; } print_r($array2);위해이
Array ([0] => Array ([name] => The Lord of the Rings Trilogy) [1] => Array ([name] => Snatch)
[2] => Array ([name] => The Social Network Movie) [3] => Array ([name] => Scarface)
[4] => Array ([name] => Once Upon a Time in the West) [5] => Array ([name] => Legend of the Guardians: The Owls of Ga'Hoole) [6] => Array ([name] => Once Upon a Time in America)
[7] => Array ([name] => Butch Cassidy and the Sundance Kid) [8] => Array ([name] => Fracture)
[9] => Array ([name] => Invictus) [10] => Array ([name] => Pride and Glory) [11] => Array ([name] => Casablanca))
를 인쇄합니다.
$match= array_intersect($array1, $array2); print_r($match);결과의 의지
Array ([0] => Array ([name] => Snatch) [1] => Array ([name] => The Social Network Movie)
[2] => Array ([name] => Death Note) [3] => Array ([name] => Titanic)
[4] => Array ([name] => Once Upon a Time in the West))
하지만 일반적인 영화는 다음과 같습니다Snatch , The social network movie , once upon a time in the west
왜 mysql에서 그렇게하지 않습니까? – zerkms
이 코드를 소스에서 직접 복사/붙여 넣기 했습니까? 여기 $ query2와 같은 user_id로부터 $ query3이 나오기 때문에 $ array1에있는 모든 것을 출력 할 것입니다. – tkm256
@zerkms : DB 디자인이 좋지 않기 때문에 –