我有三個表(個人,組&記錄標籤),並希望使用它們之間的信息來製作記錄標籤中的人員列表。例如:它應該找到公司ID爲#的個人和組,並列出它們。如何在沒有重複結果的情況下正確創建它?3表= 1列表(已解決)
// Connect to database
include "mysqli_connect.php";
// Set variables
$url_num = $_GET['company_id'];
$company_num = "";
$company_members = "";
$company_members2 = "";
//Check for artist id pagination
if(is_numeric($url_num)){
$company = intval($url_num);
}else{
$company = 1;
}
// Construct our join query
$sqli = "SELECT DISTINCT * FROM recordlabels
INNER JOIN individuals ON individuals.companyID=recordlabels.companyID
INNER JOIN groups ON groups.companyID=recordlabels.companyID
WHERE recordlabels.companyID = '{$company}'";
// Create results
$result = mysqli_query($link, $sqli);
//Check for albums
$totalmembers = mysqli_num_rows($result);
// Checking if query is successful
if($result){
// Print out the contents of each row into a table
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
// Assign value of column if not empty, otherwise "DamJuNoImage" (Thanks to Jonathan Sampson from Stack Overflow)
$companyen = empty($row["companyen"])
? "Unknown"
: $row["companyen"];
$companyko = empty($row["companyko"])
? "Unknown"
: $row["companyko"];
$companyType = empty($row["companyType"])
? "Unknown"
: $row["companyType"];
$founded = empty($row["established"])
? "Unknown"
: $row["established"];
$founder = empty($row["companyFounder"])
? "Unknown"
: $row["companyFounder"];
$information = empty($row["information"])
? "Unknown"
: $row["information"];
$location = empty($row["companyLocation"])
? "Unknown"
: $row["companyLocation"];
$homepage = empty($row["companyPage"])
? "#"
: $row["homepage"];
$solopic = empty($row["solopic"])
? "DamjuNoImage"
: $row["solopic"];
$soloen = empty($row["soloen"])
? "Unknown"
: $row["soloen"];
$solokn = empty($row["solokn"])
? "Unknown"
: $row["solokn"];
$grouppic = empty($row["grouppic"])
? "DamjuNoImage"
: $row["grouppic"];
$groupen = empty($row["groupen"])
? "Unknown"
: $row["groupen"];
$groupkn = empty($row["groupkn"])
? "Unknown"
: $row["groupkn"];
$company_members .= '<li><a href="#">
<div class="image"><img src="pathhere/' . $solopic . '"></div>
<p class="datatitle2">' . $soloen . '</p>
<p class="data-info2">' . $solokn . '</p>
</a></li>';
$company_members2 .= '<li><a href="#">
<div class="image"><img src="pathhere' . $grouppic . '"></div>
<p class="datatitle2">' . $groupen . '</p>
<p class="data-info2">' . $groupkn . '</p>
</a></li>';
$listofmembers = $company_members . $company_members2;
} // End of while statement
}else{
echo "No people under $companyen";
} // End of If statement
給(希望)更好的視覺效果。
- 鮑勃(個人)
- 麗莎(個人)
- 工坊(集團)
尋求幫助之前,我測試了這樣的結果:
- 鮑勃(個人)
- 麗莎(個人)
- 工坊(集團)
- 工坊(集團)
那是因爲我把個人和羣體的輸出在自己獨立的價值。然後我回應我認爲會出錯的$var1 . $var2
。
更新:如果沒有人能弄明白,我會重做我的數據庫和表格。謝謝你試圖幫助的所有人。
'SELECT DISTINCT <實field-list> FROM ...'而不是'SELECT * FROM ...' –
@EugenRieck是對的,但你真的應該問一個問題,以便我們知道你想要什麼。 – Rufinus
大聲笑哎呀我被吸進解釋並忘了添加問題 – taeja87