Hi, I'm skinning PHPas but I want to change how the games are displayed on the front page. I'm trying to display the four top rated games in the database. My code looks like:
Code:
<?
$x = 0;
$gamelist = "";
$maingame = "";
$sql_query2 = "SELECT * FROM games where gamestatus = 1 ORDER BY rating ASC LIMIT 4";
$result2 = mysql_query($sql_query2);
if(mysql_num_rows($result2))
{
// Gets all the game information if available
while($row = mysql_fetch_array($result2))
{
$x++;
$gameid = $row['gameid'];
$gametitle = stripslashes($row['gametitle']);
$gamedesc = stripslashes($row['gamedesc']);
$gamekeywords = $row['gamekeywords'];
$gamefile = $row['gamefile'];
$gameheight = $row['gameheight'];
$gamewidth = $row['gamewidth'];
$category = $row['category'];
$timesplayed = $row['timesplayed'];
$rating = $row['rating'];
$gameicon = $row['gameicon'];
$gamelocation = $row['gamelocation'];
$iconlocation = $row['iconlocation'];
// Limit the # of characters in the Game Description
if (strlen($gamedesc)> 35)
$gamedesc = substr($gamedesc,0,35)." ...";
$title = make_friendly($gametitle);
if ($iconlocation == 1)
$gameicon = $gameicon;
elseif (!empty($gameicon))
$gameicon = $base_url."games/images/".$gameicon;
if (empty($gameicon))
$gameicon = $defaulticon;
if ($rewrite ==0)
$gamelink = $base_url."index.php?action=playgame&gameid=".$gameid;
else
$gamelink = $base_url.$sedir."/".$gameid."/".$title;
$maingame = "<div class=\"game_listing\"><a href=\"$gamelink\"><img src=\"$gameicon\" alt=\"$gametitle icon\" class=\"game_img\"/></a><a href=\"$gamelink\">$gametitle</a><p class=\"game_desc\">$gamedesc</p><p class=\"clear\"></p></div>";
} }
$content = $content."<div class=\"contentheader\">
<p class=\"top_rated\">
Top Rated Games
</p>
</div>
<div class=\"contentarea_right\">$maingame<p class=\"clear\"></p>
</div>";
?>
<?=$content;?>
It seems to be working apart from it only shows one game (the one with the highest rating) instead of four.
Any ideas where I'm going wrong?