我有表得到從多個MySQL表和顯示數據在PHP(arrray)
- 電影表moviesdb;
- 數據表
- 者表
- 字符表
- 模式表
MOVIES TABLE
===============================================
CODE : TITLE : DESCRIPTION YEAR
=====================================================
1 IRON MAN 3 xxxxx 2013
2 STAR WARS xxxxx 2013
個人表
===============================================
CODE : NAME: BIRTH_DATE
=====================================================
1 SHANE BLACK 1965:04:04 00:00:00
2 ROBERT DOWNEY 1965:04:04 00:00:00
3 Gwyneth Paltrow 1965:04:04 00:00:00
4 Don Cheadle 1965:04:04 00:00:00
個字符的表
===============================================
PERSON : NAME: MOVIE
=====================================================
2 TONY STARK 1
3 PEPPER POTTS 1
4 Col. James Rhodes 1
模式表
===============================================
CODE : NAME :
=====================================================
1 DIRECTOR
2 WRITER
3 ACTOR
4 CHARACTER
數據表格
===============================================
CODE : MOVIE : PERSON MODE
=====================================================
1 1 1 1
2 1 2 3
3 1 3 3
4 1 4 3
FINAL答案將是這樣的:
===============================================
CODE : MOVIE TITLE : DIRECTOR : ACTORS CHARACTERS
=====================================================
1 IRON MAN 3 SHANE BLACK Robert Downey Jr. Tony Stark
Gwyneth Paltrow Pepper Potts
Don Cheadle Col. James
MySQL命令是:
SELECT
movies.title,
movies.year,
persons.name,
modes.name,
persons.birth_date,
characters.name
FROM
data
INNER JOIN movies ON (data.movie = movies.code)
INNER JOIN persons ON (data.person = persons.code)
INNER JOIN modes ON (data.mode = modes.code)
INNER JOIN characters ON (persons.code = characters.person)
AND (characters.movie = data.movie)
WHERE
MOVIES.code = '1'
SQL Command WORKS fine;
我有PHP代碼
$movie_query = mysql_query("
SELECT
movies.title,
movies.year,
persons.name,
modes.name,
persons.birth_date,
characters.name
FROM
data
INNER JOIN movies ON (data.movie = movies.code)
INNER JOIN persons ON (data.person = persons.code)
INNER JOIN modes ON (data.mode = modes.code)
INNER JOIN characters ON (persons.code = characters.person)
AND (characters.movie = data.movie)
WHERE
MOVIES.code = '1';");
WHILE ($rows = mysql_fetch_array($movie_query))
{
$movie_code = $rows['movies'.'code'];
$movies_title = $rows['movies'.'title'];
$movies_year = $rows['movies'.'year'];
$movies_date_add = $rows['movies'.'date_add'];
$movies_tagline = $rows['movies'.'tagline'];
echo "$movie_code<br>$movies_title<br>$movies_year<br>$movies_date_add<br>$movies_tagline<br>";
}
任何問題問題,我的PHP代碼..? (似乎SQL命令不一樣的MySQL語法)
in $ movie_query remove;並使用除mysql以外的其他內容。 – Mihai
啓用'error_reporting(E_ALL);'並使用'print_r($ rows)'來查看字段名稱與循環中使用的不同(您將PHP中的表名和列連接起來)。 – mario
@Mihai我明白刪除「;」但「使用別的不是MySQL」?你是否建議他使用不同的數據庫? 和所有爲什麼倒票? – mcgrailm