php - How do I retrieve the last 10 records from mysql database table? -
I have a strange problem when I run this script, I get 10 records from the database but they're all exactly the same. Are there. I do not know what I'm doing wrong or how to fix it. Please help me.
I want to see table AMCMS_highscores, AMCMS_users, AMCMS_games inside the AMCMS_highscores table, get the last 10 records, but only where the field game ID is 1997 for example. Any help is appreciated.
select $ data = Q ( "Kren` AMCMS_highscores`.`primkey`,` AMCMS_highscores`.`gameid`, `AMCMS_highscores`.`score`,` AMCMS_users`. `Username 'AMCMS_Hycomers``States, AMCMS_Highscores,' UserMess', 'AMCMS_Game'. 'Primki', 'AMCMSGame'. From Gammam 'AMCMS_Hauscocker', 'AMCMS_Game', 'AMCMS_UJs' where' AMCMS_ HighScore ' .`gameid` = '$ gameid' and `AMCMS_highscores`.`userkey`! =` AMCMS_users`.`userkey` and `AMCMS_highscores`.`gameid` =` AMCMS_games`.`primkey` and `` AMCMS_highscores`k`status AMCMS_ Aiscoras` Dwara` = "approved" orders. "Pramiki 'Diissi range 0, 10") of; Print "& lt; Table Range Cellpadding = 3" gt; "; While ($ info = mysql_fetch_array ($ data))" Print "" "; Print" & lt; Th> ID: & lt; / Th & gt; & Lt; Td> "$ info ['userkey']." & Lt; / Td> & Lt; / Tr & gt; "Print; Print" & lt; / Table> ";
Here is a format version of the query:
select 'AMCMS_highscores`.`primkey`,` AMCMS_highscores` .`gameid`, `AMCMS_highscores`.` from score`, `AMCMS_users`.`username`,` AMCMS_highscores`.`status`, `AMCMS_highscores`.`userkey`,` AMCMS_games`.`primkey`, `` AMCMS_highscores` AMCMS_games`.`gamename`, `AMCMS_games` `AMCMS_users` where` AMCMS_highscores`.`gameid` = '$ gameid' and `AMCMS_highscores`.`userkey`! =` AMCMS_users`.`userkey` and `AMCMS_highscores`.`gameid `= 'AMCMS_games```primkey` and` AMCMS_highscores`.`status` =' AMCMS_highscores` by `command` Dynamic '' DISC limit 0, 'Approved' 10
< P> Oh, I meant to copy that but I did not When it's "=" sign (highscores.userkey = users.userkey), I get a blank query so that it can not be corrected: (
I hope that this query Understanding would be easier :)
here The result is:
(under game)
BTW, when you post it, how do you do your query? I clicked on the code button and only the first line of code was coded.
If you are trying to select the record from AMCMS_users
, whose If there is no match line for AMCMS_highscores
, then you need to do a LEFT JOIN
, and test for zero values The associated table is a quote from here: / P>
If there is no matching line for the correct table in
ON
orUsage
sectionLEFT JOIN
, right A column with all the columns for the column The person is used. You can use this fact to find rows in a table that are not equivalent to any other table:
Your query will therefore appear more like this:
select `Amkans_ःiskors`k`preemkey`,` Amkans_ःiskors`k`gmeid`, `Amkans_ःiskors`k`scor`,` Amkans_ussers`k`ugrnam`, `Amkans_ःiskors`k`stets`,` Amkans_ःiskors Include `AMCMS_users`` AMCMS_highscores`.`userkey` = `AMCMS_users`.`userkey` to` `include` `` `` `" _ "_" _ " AMCMS_games` at `AMCMS_highscores`.gameid```` AMCMS_games```primkey`` where` AMCMS_highscores`.`gameid` = '$ gamma D 'and `AMCMS_highscores`.`status` = and` AMCMS_users`.`userkey` = gave no orders approved by the `AMCMS_highscores`.`' Praimki Diissi frame 1, 10;
Ignoring other situations for a moment, looking at every line in your query AMCMS_highscores
, and it's AMCMS_highscores Where
AMCMS_highscores
. userkey
is not equal to AMCMS_users
. userkey
. This will generate many matching rows to see what's happening, remove the LIMIT
section from your query.
Comments
Post a Comment