Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: SimplePlan2k8 - heinäkuu 25, 2008, 09:55:50 AP

Otsikko: Any way to exclude results in MySQL?
Kirjoitti: SimplePlan2k8 - heinäkuu 25, 2008, 09:55:50 AP
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?
Otsikko: Re: Any way to exclude results in MySQL?
Kirjoitti: vbgamer45 - heinäkuu 25, 2008, 11:59:12 IP
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.
Otsikko: Re: Any way to exclude results in MySQL?
Kirjoitti: SimplePlan2k8 - heinäkuu 27, 2008, 11:28:33 AP
Yes I am using it on a PHP page. How do you do this skip?
Otsikko: Re: Any way to exclude results in MySQL?
Kirjoitti: vbgamer45 - heinäkuu 27, 2008, 11:59:01 AP
You could use a counter $counter = 0;   and in the loop do $counter++;   If the counter is greater than 2 then show the results.
Otsikko: Re: Any way to exclude results in MySQL?
Kirjoitti: SimplePlan2k8 - heinäkuu 27, 2008, 01:20:32 IP
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>";
}
?>
Otsikko: Re: Any way to exclude results in MySQL?
Kirjoitti: H - heinäkuu 27, 2008, 01:34:37 IP
Not a SQL expert but can you not just use OFFSET?
Otsikko: Re: Any way to exclude results in MySQL?
Kirjoitti: vbgamer45 - heinäkuu 27, 2008, 02:26:38 IP
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>";
}
?>
Otsikko: Re: Any way to exclude results in MySQL?
Kirjoitti: SimplePlan2k8 - elokuu 01, 2008, 01:50:33 IP
Fantastic
Thank you so much :)