假设我的数据库中有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图像选择另一个随机图像?
最佳答案
简单:将您的第一个查询的ID作为not in
填充到第二个查询中:
SELECT ...
FROM yourtable
WHERE idField NOT IN (x,y,z,p,q,r)
这会将它们从第二个查询的结果中排除。