The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> MSQL query.. just not working! *n00b here*
svenny1
post Nov 4 2007, 12:12 PM
Post #1


Newbie
*

Group: Members
Posts: 17
Joined: 16-June 07
Member No.: 3,094



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Nov 5 2007, 10:23 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th April 2024 - 09:26 AM