-1

只是最近转换PHP PDO Query,我有点困惑ORDER BY

我有 2 个字段名和值我想订购这是我需要转换为 PDO 的旧数据

问题:我如何ORDER BY在 PDO 中使用

$results = mysqli_query($con,"SELECT * FROM `supplies` ORDER BY field(citname,'Dejan Vemic','MitkoEzio','Sebatay','Ash2Ash','Dexter Sinister','dracoolinho','KALE Podgorica','Omerta NK','Pobor','Rachsuchtig','Snake0307','SrpskaCG','Vojvoda1389') ASC, field(day,'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')");

如果有人请帮忙,这是我目前的声明

$sql = 'SELECT citid, citname, worked, rankpoints, supplyamount, wassupplied, date, day FROM supplies';
4

1 回答 1

1

由于您没有绑定变量,您可以使用query() 注意这ASC是默认的,不是必需的。

 $sql ="SELECT * FROM `supplies` ORDER BY field(citname,'Dejan Vemic','MitkoEzio',
'Sebatay','Ash2Ash','Dexter Sinister','dracoolinho','KALE Podgorica','Omerta NK',
'Pobor','Rachsuchtig','Snake0307','SrpskaCG','Vojvoda1389'), 
 field(day,'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday',
 'Saturday')":

foreach ($conn->query($sql) as $row) {
    print $row['citid'] . "\t";
    print $row['citname'] . "\t";
    //ETC
}
于 2013-07-01T00:13:33.777 回答