2014-05-20 43 views
0

所以我們可以說我在我的數據庫30個條目,我選擇第7讓我的第一頁上是這樣的:扣除先前的值

$qryRandomGallery = "SELECT a.Titel, a.KW, a.KWKidsID, a.KWKidsBeschrijving, b.ScoreAfbeelding, c.GebruikersNaam 
         FROM tblKWKids AS A 
         LEFT JOIN tblScore AS b 
         ON a.ScoreID = b.ScoreID 
         LEFT JOIN tblUser as C 
         ON a.UserID = c.UserID 
         ORDER BY RAND() 
         LIMIT 6"; 
if ($stmtRandomGallery = mysqli_prepare($dbconn, $qryRandomGallery)) { 
      mysqli_stmt_execute($stmtRandomGallery); 
      mysqli_stmt_bind_result($stmtRandomGallery, $KWTitel, $KWURL, $KWID, $KWKiddyBeschrijving, $ScoreAfb, $USER); 
      mysqli_stmt_store_result($stmtRandomGallery); 
} 

$qryRandomGalleryBIG = "SELECT a.Titel, a.KW, a.KWKidsID, a.KWKidsBeschrijving, b.ScoreAfbeelding, c.GebruikersNaam 
         FROM tblKWKids AS A 
         LEFT JOIN tblScore AS b 
         ON a.ScoreID = b.ScoreID 
         LEFT JOIN tblUser as C 
         ON a.UserID = c.UserID 
         ORDER BY RAND() 
         LIMIT 1"; 
if ($stmtRandomGalleryBIG = mysqli_prepare($dbconn, $qryRandomGalleryBIG)) { 
      mysqli_stmt_execute($stmtRandomGalleryBIG); 
      mysqli_stmt_bind_result($stmtRandomGalleryBIG, $KWTitelB, $KWURLB, $KWIDB, $KWKiddyBeschrijvingB, $ScoreAfbB, $USERB); 
      mysqli_stmt_store_result($stmtRandomGalleryBIG); 
} 

,然後以此作爲我的PHP

while(mysqli_stmt_fetch($stmtRandomGallery)){ 
$content .= '<div>'; 
$content .= '<a href="galerij.php?id=' . $KWID . '">'; 
$content .= '<img src="' . $KWURL . '" title="' . $KWTitel . '" alt="' . $KWTitel . '" class="image">'; 
$content .= '<h5>' . $KWTitel . ' door: ' . $USER . '</h5>'; 
$content .= '<p>' . $KWKiddyBeschrijving . '</p>'; 
$content .= '<img src="' . $ScoreAfb . '" title="Score" alt="Score" class="img">'; 
$content .= '</a>'; 
$content .= '</div>'; 
} 
while(mysqli_stmt_fetch($stmtRandomGalleryBIG)){ 
$content .= '<h2>Uitgelicht werk van ' . $USERB . '</h2>'; 
$content .= '<a href="galerij.php?id=' . $KWIDB . '">'; 
$content .= '<img src="' . $KWURLB . '" title="' . $KWTitelB . '" alt="' . $KWTitelB . '" id="image">'; 
$content .= '<h3>' . $KWTitelB . ' door: ' . $USERB . '</h3>'; 
$content .= '<h4>' . $KWKiddyBeschrijvingB . '</h4>'; 
$content .= '<img src="' . $ScoreAfbB . '" title="Score" alt="Score" id="score">'; 
$content .= '</a>'; 
} 

現在,我該如何從第一個stmt中排除結果,爲我的BIG圖像選擇另一個隨機圖像?

回答

0

簡單:你的第一個查詢的識別碼與它們塞進第二查詢作爲not in

SELECT ... 
FROM yourtable 
WHERE idField NOT IN (x,y,z,p,q,r) 

這將從第二個查詢的結果中排除。

+0

因此,例如,我將使用此代碼; 'FROM tbKWKids WHK KWKidsID NOT IN('。$ stmtRandomGallery。','。$ stmtRandomGalleryBIG。')' – Mattsie