我有2個數據庫表用戶和圖庫,如果用戶有一個圖庫,頁面將顯示無限配置文件,它將顯示在該圖像下。echo僅從數據庫中返回一個結果
當前在DB用戶中有2個用戶1個有5個畫廊圖像用戶2沒有。
用戶和圖庫表由兩個表中的D = ID字段連接。
第一位用戶在他的個人資料下顯示他的畫廊,但用戶2完全不顯示,每個新用戶和畫廊(如果他們有一個)都顯示在對方之下,就像列表一樣。但它回聲了第一個用戶和他的畫廊,就是這樣..
如果我在查詢WHERE U.ID = 1或2中的WHERE U.ID = U.ID它會顯示兩個用戶只是不在同時在列表..
CREATE TABLE `users` (
`ID` int(11) UNSIGNED NOT NULL,
`Email` varchar(255) NOT NULL,
`FullName` varchar(300) NOT NULL,
`JobTitle` varchar(300) NOT NULL,
`Bio` text,
`Photo` text,
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `gallery` (
`GalleryID` bigint(11) UNSIGNED NOT NULL,
`ID` int(11) DEFAULT NULL,
`GalleryImage` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
<?php
$stmt = $db->prepare("
SELECT U.ID,
U.FullName,
U.Email,
U.JobTitle,
U.Bio,
U.Photo,
group_concat(G.GalleryImage) as GalleryImage
FROM users as U
join gallery as G
ON U.ID = G.ID
WHERE U.ID = U.ID
");
$stmt->execute();
$result = $stmt->get_result();
while ($row = mysqli_fetch_assoc($result)) {
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleryImage = explode(',', $row['GalleryImage']);
if (isset($Photo) && ! empty($Photo)) {
$ProfileImage = "$Photo";
} else {
$ProfileImage= "avatar.jpg";
}
echo "<div class='container team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='$ProfileImage'>
</div>
<div class=\"col-md-6\">
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>
</div>";
echo "
<br>
<br>
<br>
";
echo "<div class='container team-wrap'>";
foreach ($GalleryImage as $img){
if (isset($img) && ! empty($img)) {
//Display this row as many times as needed by data in this row.
echo "<img style='height: 100px; width: 100px;' src='cdn/assets/gallery/$img'>";
} else {
echo "NO IMAGES";
}
}
}
echo"</div>";
?>
那麼是什麼問題?你總是可以使用[mysqli_num_rows](http://php.net/manual/en/mysqli-result.num-rows.php)來檢查返回的行數。 – Pyromonk
SELECT G.GameID,G.GameName,G.GameCover,group_concat(M.ModName)FROM G作爲G加入Mod作爲G.GameID = M.GameID組作爲G.GameID – JYoThI
我假設這一定是相當困難的很多意見,但沒有答案我現在不覺得這麼糟糕 – Case