php - 从 mysql 数据库中的每个值获取最后的结果

标签 php mysql mysqli

我有一个数组,其中包含马匹列表。

我希望能够遍历该数组并拉出每匹马的最后结果。

目前我的代码如下所示:

select count(*),Horse,Place from horsesrp where Horse In (".$horsearray.")")

我如何修改它,以便只显示数组中的马的最后结果。

下面是我的数组的输出

Array ( [0] => Sky Watch [1] => Sunny Ledgend [2] => Jupiter Rex [3] => Storm Alert [4] => Alanjou [5] => Strike Fast [6] => Mister Grez [7] => Stone Light [8] => Free World [9] => Humbel Ben [10] => Honour A Promise [11] => Sassanova [12] => Binowagh Bay [13] => Lady Garvagh [14] => Ovilia [15] => Agent Fedora [16] => Dazzling Rita [17] => Moving Waves [18] => Pandy Wells [19] => Frank N Fair [20] => Ruby Valentine [21] => Pennies And Pounds [22] => Never Never [23] => Bertie Moon [24] => Definite Future [25] => If It Be Your Will [26] => Kapstadt [27] => Kayf Blanco [28] => Neworld [29] => Polvere D'oro [30] => Restraint of Trade [31] => Broome Lane [32] => Fine Lily [33] => Pembridge [34] => Capard King [35] => Central School [36] => Coologue [37] => Ma du Fou [38] => Quintano [39] => The Mobb [40] => The Western Force [41] => Youngdocgallagher [42] => Tara Mac [43] => No Principles [44] => Raid Stane [45] => Elton Fox [46] => Minella Bliss [47] => Midnight Dove [48] => Saga de Tercey [49] => Iktiview [50] => Nordic Nymph [51] => Do Be Dashing [52] => Tantalized [53] => Apache Chief [54] => Black Jack Rover [55] => Charlie Cook [56] => Freddie Bear [57] => Rambo [58] => The Late Shift [59] => Tropical Sunshine [60] => Western Xpress [61] => Vitarra [62] => Azure Amour [63] => My Mistress [64] => Royal Roslea [65] => Beach Plaza [66] => Dat Il Do [67] => Surelookit [68] => Bollywood Dream [69] => Dutch Fredie G [70] => Suffolk Sky [71] => Trikasana [72] => Lettuce Snow [73] => Tommy's Secret [74] => Freddy With A Y [75] => Starlight Symphony [76] => Embankment [77] => Gracious George [78] => Presumido [79] => Until Midnight [80] => Gannicus [81] => Next Stop [82] => Woodbridge [83] => Elusive Ellen [84] => Evident [85] => Bobby Benton [86] => Kuwait Star [87] => Ruban [88] => Senator Matt [89] => Strictly The One [90] => Belahodood [91] => Filosofo [92] => Made With Love [93] => Silver Secret [94] => Ladyhawk [95] => Tiger Stone [96] => Thane of Cawdor [97] => Maison Brillet [98] => Idol Deputy [99] => Takeitfromalady [100] => Mcbirney [101] => Bennelong [102] => Eurato [103] => Day Of The Eagle [104] => Fair Comment [105] => Gracefilly [106] => Softly She Treads [107] => Munsarim [108] => Bowsers Bold [109] => Eastward Ho [110] => Burning Blaze [111] => Trader Jack [112] => Brigliadoro [113] => Midnight Rider [114] => Good Luck Charm [115] => Ertikaan [116] => Palace Moon [117] => Don't Be [118] => Toga Tiger [119] => Footstepsintherain [120] => Polar Kite [121] => Conry [122] => Sheikh The Reins [123] => Whaleweigh Station [124] => Light From Mars [125] => Strategic Force [126] => Lady Brigid [127] => Secret Asset [128] => Nonno Giulio [129] => Head Space [130] => Time And Place [131] => Secret Millionaire [132] => Drive On [133] => Clockmaker [134] => Angus Glens [135] => Dont Take Me Alive [136] => Greeleys Love [137] => Arashi [138] => Addazero [139] => Montaff [140] => Guards Chapel [141] => Leyland [142] => Artisan [143] => Golden Bird [144] => Sparkling Ice [145] => Rookery [146] => Haines [147] => Ballyfarsoon [148] => Bahango [149] => Kyrenia Castle [150] => Bahama Blue [151] => Desert Apostle [152] => Vivre La Reve [153] => Thataboy [154] => Royal Acquisition [155] => Pensax Lad [156] => Captain Whoosh [157] => Scoreline [158] => West Coast Dream [159] => Profile Star [160] => Pearl Noir [161] => Bilash [162] => Black Dave [163] => Argent Touch [164] => Mr Mo Jo [165] => Island Express [166] => Sir Billy Wright [167] => Summersault [168] => Windy Miller [169] => Zat Be Zat [170] => Nelson's Pride [171] => Princess Rose [172] => Zaria [173] => Shyron [174] => Monsea [175] => Silverware [176] => Corporal Maddox [177] => Mr Bossy Boots [178] => Loyalty [179] => Smokethatthunders [180] => Order Of Service [181] => Ace Master [182] => Rasaman [183] => Beedee [184] => Rich Again [185] => Ruggero [186] => Tukitinyasok [187] => Keeper's Ring [188] => Catching Zeds [189] => Pipers Piping [190] => Tsarglas [191] => Key To Your Heart [192] => Katmai River [193] => Spokesperson [194] => Navajo Dream [195] => Courtezan [196] => Ambella [197] => Russian Ice [198] => Boboli Gardens [199] => Sarlat [200] => Look Here's Al [201] => Postillion [202] => Cherry Tiger [203] => Celestial Dawn [204] => Previous Acclaim [205] => Dutch Lady Roseane [206] => L'inganno Felice [207] => Take Two [208] => A Little Bit Dusty [209] => Amazing Star [210] => Aneedh [211] => Dialogue [212] => Gabrial The Duke [213] => Swift Cedar [214] => Menelik [215] => Gilmer [216] => Sheriff Of Nawton [217] => Dansili Dutch [218] => Disclosure [219] => Royal Trooper [220] => Helmsley Flyer [221] => Taroum [222] => Reality Show [223] => Pim Street [224] => Cropley [225] => Dhaular Dhar [226] => Qibtee [227] => Uganda Glory [228] => Master Of Song [229] => Cabuchon [230] => Percys Princess ) 

数据库保存赛马结果,因此我想获取每匹马的最后结果

运行以下 sql 命令将产生以下结果: “从 horsesrp 中选择地点,马匹,其中马匹位于 (".$horsearray.")”

Haines Rich Again Uganda Glory Rich Again Sarlat Rich Again Gracious George Lady Brigid Rich Again Smokethatthunders Dialogue L'Inganno Felice Pearl Noir

因为 cna be saw rich Again 显示了几次,我只想得到最后的结果(仅 1 个结果)

我已经尝试过"select Place, Horse from horsesrp where Horse In (".$horsearray.") limit 1"但这只是返回第一匹马海恩斯

最佳答案

我想我明白你想做什么......

选择 (从 horserp 中选择地点作为 rp,其中 rp.Horse = Horse Order By id DESC LIMIT 1)作为 地点, 马 从 马srp 马在 (".$horsearray.")")

我希望 id 是您的主键并且是一个整数。也应该适用于日期时间或日期列。

关于php - 从 mysql 数据库中的每个值获取最后的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27601459/

相关文章:

php - 我如何编写两个链接到同一页面的不同工作?

php - YouTube API 网站 URL token 限制?

c# - 如何将数据库中的多个图像显示为统一

Mysql:重复键更新触发不起作用

javascript - 使用 location.reload() 似乎可以防止 php 更新数据库

php - 与 mysqli() 的连接不起作用,为什么?

php - 如何在我的 html 中制作志愿计算器

php - PDO 对象可以存储在 session 中吗?

java - 将 MySQL 连接器 JAR 放在我的 WAR 的 WEB-INF/lib 中而不是在 $CATALINA_HOME/common/lib 中?

php - 如何在登录表单php上使用密码验证