Help - Search - Members - Calendar
Full Version: MSQL query.. just not working! *n00b here*
HTMLHelp Forums > Programming > Databases
svenny1
right some may remmeber me form before, i have a gaming website and am using querys etc to display top 5 games or what ever. That was all fine and dandy until this problem...

I have an ID for each game, and i now have been able to show the latest games, in this case by using a query on the ID coloumn selecting only the last 3 and displaying them DESC. Here is my code.


CODE

<?php
// top_games.php
// Make sure it works
define('IN_SITE', true);

// Grab the connect.php file so we can connect
require_once('connect.php');

// Get the results, and order them by 'count' from highest to lowest
// If you wanted the top 100 only, add this after DESC and before ":
// LIMIT 1,100
$result = mysql_query("SELECT * FROM `Action` ORDER BY `id` DESC LIMIT 0,3") or die(mysql_error());

// Output table:

?>
    </div>
    <table width="146" height="52" border="0" align="left" cellpadding="2" cellspacing="0" style="border: 0px solid #000000">
      <?php

// Run a loop through the results
while ($row = mysql_fetch_array($result)) {
?>
      <tr>
        <td width="44"><img src="<?php echo $row['image']; ?>" width="25" height="25" border="0" /></td>
        <td width="138"><div align="center"><a href="g_<?php echo strtolower(preg_replace("/\s/", "_", $row['game_name'])); ?>.php"><?php echo $row['game_name']; ?></a></div></td>
      </tr>
      <?php
// End the table
}
?>
    </table>



My problem is that, the query shows the last 2 games on the list, but also shows ID 1. So for example, i have just added 3 new games, game 9 10 and 11. The query should show 9 10 and 11, however it seems to show 1, 10 and 11. That is my problem is there anybody out there who can help?

Thanks in advance.


PS - sorry my first post was in the wrong category just realised, so reposted it here.
Brian Chandler
You need to debug your program. It's not reasonable to hope that someone else will just gaze at it and spot the mistake.

First, print the main bits (ID etc) from each row, so you can see what you are getting. If this is what you expected, then the error occurs after this point; if it's not what you expected, before... thus you progressively narrow the range containing the problem.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.