Jump to content

PHP for each category?


adamlacombe

Recommended Posts

This is a PHP/MYSQL kind of question, but I was wondering if it was possible to  show a row from each that "such and such = blah".

So for example Im making an arcade site so I want the front page to have a game from each category.

I hope that made some sense, its kind of hard to explain I think.

Thanks in advanced!

Link to comment
https://forums.phpfreaks.com/topic/164791-php-for-each-category/
Share on other sites

Hmm...

its not seeming to work.

This is what I got all together:

<table>
<?
$game="Select distinct(game_cat), game_name from game";

$game2=mysql_query($game) or die("Could not get games");

while($game3=mysql_fetch_array($game2))

{

   echo'<tr align="left" valign="top"> 
      <td align="left" width="71"><span> 
        <a href="index.php?action=game&id='.$game3[game_id].'">';

echo'
        <img src="game/thumbs/'.$game3[game_name].'.jpg" height="71" width="71" />';

echo'</a></span></td> 
      <td>
        <a href="index.php?action=game&id='.$game3[game_id].'">'.$game3[game_name].'</a>
<br />
<small>Played '.$game3[game_views].' Times</small></td></tr>';

}
?>
</table>

 

And is it possible to get the category name for each, so like it will say:

Action

--------

Game1...

 

Thanks again!

I still cant get it to work, I tried this:

<?
echo'<table>';

$r="SELECT * from game_cat";

$r2=mysql_query($r) or die("Could not get cats");

$row=mysql_fetch_array($r2);

       echo '<strong>'.$row['cat_name'].'</strong><br />';


$game="Select * FROM game GROUP BY game_cat LIMIT 0,5";

$game2=mysql_query($game) or die("Could not get games");

while($game3=mysql_fetch_array($game2))

{

   echo'<tr align="left" valign="top">
      <td align="left" width="71"><span>
        <a href="index.php?action=game&id='.$game3[game_id].'">';

echo'
        <img src="game/thumbs/'.$game3[game_name].'.jpg" height="71" width="71" />';

echo'</a></span></td>
      <td>
        <a href="index.php?action=game&id='.$game3[game_id].'">'.$game3[game_name].'</a>
<br />
<small>Played '.$game3[game_views].' Times</small></td></tr>';

}
?>
</table>

 

But it is only coming up with 3 games and it is not displaying the games from each category.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.