Uutiset:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu
Advertisement:

Any way to exclude results in MySQL?

Aloittaja SimplePlan2k8, heinäkuu 25, 2008, 09:55:50 AP

« edellinen - seuraava »

SimplePlan2k8

Hey all
Basically, I am outputting a list of data from my MySQL database, and want to ALWAYS exclude the first two results.
Any way to do this?

vbgamer45

If you are showing on a php page you can just  skip the first two using the result.

Or
http://us2.php.net/manual/en/function.mysql-data-seek.php
Which you can use to skip a couple results returned.
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

SimplePlan2k8

Yes I am using it on a PHP page. How do you do this skip?

vbgamer45

You could use a counter $counter = 0;   and in the loop do $counter++;   If the counter is greater than 2 then show the results.
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

SimplePlan2k8

Erm, I'm a bit of a novice here lol
Here is what I have currently. Where do I add this in?

$result = mysql_query("
SELECT
gamecms_article.gameId,
gamecms_article.articleId,
gamecms_article.timestamp,
gamecms_article.categoryId,
gamecms_articleRatings.articleId,
gamecms_articleRatings.ratingId,
gamecms_articleRatings.ratingText,
gamecms_articleRatings.rating,
gamecms_game.gameId,
gamecms_game.gameName,
gamecms_game.systemId
FROM
gamecms_article
LEFT JOIN
gamecms_articleRatings
ON
gamecms_article.articleId = gamecms_articleRatings.articleId
LEFT JOIN
gamecms_game
ON
gamecms_article.gameId = gamecms_game.gameId
WHERE ratingId='1'
AND systemId='1'
AND categoryId='1'
ORDER BY timestamp DESC
LIMIT 5");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
print
"<tr><td>
<center><a href = 'http://www.euronintendo.co.uk/review.php?articleId=".$row{'articleId'}."&page=1'><b class='style2'>".$row{'gameName'}."</b></a></center>
</td><td width='50px'>
<center>".$row{'rating'}."%</center>
</td></tr>";
}
?>

H

Not a SQL expert but can you not just use OFFSET?
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

vbgamer45

Try this

$result = mysql_query("
SELECT
gamecms_article.gameId,
gamecms_article.articleId,
gamecms_article.timestamp,
gamecms_article.categoryId,
gamecms_articleRatings.articleId,
gamecms_articleRatings.ratingId,
gamecms_articleRatings.ratingText,
gamecms_articleRatings.rating,
gamecms_game.gameId,
gamecms_game.gameName,
gamecms_game.systemId
FROM
gamecms_article
LEFT JOIN
gamecms_articleRatings
ON
gamecms_article.articleId = gamecms_articleRatings.articleId
LEFT JOIN
gamecms_game
ON
gamecms_article.gameId = gamecms_game.gameId
WHERE ratingId='1'
AND systemId='1'
AND categoryId='1'
ORDER BY timestamp DESC
LIMIT 5");

$counter = 0;
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$counter++;

if ($counter < 2)
continue;




print
"<tr><td>
<center><a href = 'http://www.euronintendo.co.uk/review.php?articleId=".$row{'articleId'}."&page=1'><b class='style2'>".$row{'gameName'}."</b></a></center>
</td><td width='50px'>
<center>".$row{'rating'}."%</center>
</td></tr>";
}
?>
Community Suite for SMF - Grow your forum with SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com - Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

SimplePlan2k8


Advertisement: