我相信你正在尋找的查詢是:
SELECT t1.file_title, t1.file_name, t1.file_dir,
t3.books_title, t3.books_author, t3.books_publisher
FROM first_table t1, second_table t2, third_table t3
WHERE t1.file_id=t2.file_id AND
t2.books_id=t3.books_id
這裏假設你的表的名稱是first_table
,second_table
和third_table
。隨意修改。
要使用這個結果在PHP中,你可以做這樣的事情:
$sql = "SELECT t1.file_title, t1.file_name, t1.file_dir, " .
" t3.books_title, t3.books_author, t3.books_publisher " .
"FROM first_table t1, second_table t2, third_table t3 " .
"WHERE t1.file_id=t2.file_id AND " .
" t2.books_id=t3.books_id";
$query_result = mysqli_query($sql);
$data = array();
while ($row = mysqli_fetch_assoc($query_result)) {
$row_data = array();
foreach ($row as $key => $value) {
$row_data[$key] = $value;
}
array_push($data, $row_data);
}
foreach($data as $item) {
$path_to_file = $item['file_dir'] . '/' . $item['file_name'];
print "<a href='$path_to_file'>" .
$item['books_title'] .
' (Author: ' . $item['books_author'] . ', ' .
' Publisher: ' . $item['books_publisher'] . ')</a>';
print '<br>';
}
當然,HTML的輸出完全是爲了演示目的 - 我不知道你需要什麼樣的格式。關鍵件明白是:
- 件
$path_to_file
共同基礎上,$item['file_dir']
和$item['file_name']
- 讓你的鏈接(或您的按鈕,或任何你選擇使用)指向
$path_to_file
。
您可以加入3張表並獲取所有信息,然後使用循環使用file_dir/file_name生成下載鏈接 –
祝您的作業順利:) – DanFromGermany