dsff788655567 2019-06-05 18:53
浏览 61
已采纳

尝试按限制降序排序时出现语法错误

I am using the following code:

//Get latest version of regulation related to this CE Group
$rstmp = CustomQuery("
SELECT * 
  FROM EURegulations 
 ORDER 
    BY ValidFrom DESC 
 LIMIT 1 
 where CEGroupFk='".$values['CEGroupFk']."'
");
$datatmp = db_fetch_array($rstmp);

The purpose is to return the latest item in that list that is relevant to that foreign key.

I am getting the following message:

  1. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where CEGroupFk='5'' at line 1;
  2. 256;

The array seems to returning good data:

  1. Array ( [EURegulationReference] => test [EURegulationTitle] => test [ValidFrom] => 2019-06-19 00:00:00 [ValidTo] => 2019-06-28 00:00:00 [Attachment] => [CEGroupFk] => 5 [E...;
  2. Array ( [EURegulationPk] => 2 ) ;

I am assuming that there is a problem with my customquery code but cannot see it?

  • 写回答

1条回答 默认 最新

  • douhao2026 2019-06-05 18:57
    关注

    The order by clause must be placed after the where clause

    $rstmp = CustomQuery("
      SELECT * FROM EURegulations 
       where CEGroupFk='".$values['CEGroupFk']."'
       ORDER BY ValidFrom DESC LIMIT 1
       ");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面