2017-04-04 72 views
0

我有一個內部聯接三個表:內連接和回聲液

$result=mysql_query("SELECT singleimageupload.codrif AS codrif, 
     singleimageupload.imagesname AS bigimage, 
     uploads.imagesname AS multipleimage, 
     uploads.description AS multipledescription, 
     exposition.name, 
     exposition.author, 
     exposition.description, 
     exposition.misure, 
     exposition.date, 
     exposition.status 
    FROM exposition 
INNER JOIN singleimageupload ON singleimageupload.codrif = exposition.codrif 
INNER JOIN uploads ON uploads.codrif = exposition.codrif 
WHERE singleimageupload.firstimage = 'first' AND exposition.codrif = 'A002' 
ORDER BY exposition.codrif"); 

,我得到這樣的結果: enter image description here

我有,人有這個條件,每個上傳路徑的結果我有。

我的目標是得到這樣的: enter image description here

所以,我想合併他們的鱈魚裏夫所有上傳路徑(在這個例子中,A002)。

這是我的全碼:

<?php 



include('guestconfig/config.php'); 



$result=mysql_query("SELECT singleimageupload.codrif AS codrif, 
     singleimageupload.imagesname AS bigimage, 
     uploads.imagesname AS multipleimage, 
     uploads.description AS multipledescription, 
     exposition.name, 
     exposition.author, 
     exposition.description, 
     exposition.misure, 
     exposition.date, 
     exposition.status 
    FROM exposition 
INNER JOIN singleimageupload ON singleimageupload.codrif = exposition.codrif 
INNER JOIN uploads ON uploads.codrif = exposition.codrif 
WHERE singleimageupload.firstimage = 'first' AND exposition.codrif = 'A002' 
ORDER BY exposition.codrif"); 




while ($row = mysql_fetch_assoc($result)) { 


?> 
<table border="0"> 

<tr> 
<td> <?php echo $row['codrif']?> </td> 
</tr> 
<tr> 

<td> <?php echo $row['bigimage']?> </td> 
</tr> 
<tr> 

<td> <?php echo $row['name']?> </td> 
</tr> 
<tr> 

<td> <?php echo $row['author']?> </td> 
</tr> 
<tr> 

<td> <?php echo $row['multipledescription']?> </td> 

</tr> 
<hr> 
</table> 

<?php } ?> 

如果我解釋清楚,我希望如此,我不知道

+1

**警告**請不要**使用'mysql_ *'函數,它們已被棄用,並在最新版本的PHP中被刪除。你也開放給mysql注入,你應該看看準備好的語句,但你必須先改變庫才能做到這一點。那些'mysql_ *'函數是從90年代開始的,請將它們保留在那裏。 – Nytrix

+0

感謝您的建議。我將學習新的庫並更改mysql語句。 – James69

+1

是的,抱歉,我忘記提及這些庫名稱。我會建議「PDO」或「mysqli」。 – Nytrix

回答

1

嘗試使用GROUP_CONCAT(uploads.description)和組由singleimageupload.codrif

+0

它的工作,但我怎樣才能使用每個concat數據回聲?謝謝 – James69

+0

GROUP_CONCAT數據將以字符串形式出現,使用(逗號)爆炸。 –

+0

好的,但我怎樣才能使用單個數據進入回聲?像echo $ row ['multipledescription'] [0] echo $ row ['multipledescription'] [1]?對不起,但我真的不知道我該怎麼做。謝謝 – James69