phpdever
V2EX  ›  PHP

PHP 循环读取数据表,对其进行排序无效的问题

  •  
  •   phpdever · May 9, 2017 · 2222 views
    This topic created in 3350 days ago, the information mentioned may be changed or developed.
    各位 V 友好:

    我现在已经拿到了一个表的内容,准确的说是接口数据,接口返回 2 个字段,id、title。

    此时我 foreach 循环,利用循环的 id 去找数据库的 item 表,找出来之后想对其进行排序,比如:价格、销量、时间等等。

    但是此时我无论是进行 order 还是 limit 都是无效的,这是什么原因呢?

    代码如下:

    3 replies    2017-05-10 09:39:05 +08:00
    Light3
        1
    Light3  
       May 9, 2017   ❤️ 1
    你都 where id 的查了 如果主键是 id 的话 那么只有一条 排什么序..
    你这种循环没必要 你可以用 in 查..
    phpdever
        2
    phpdever  
    OP
       May 9, 2017
    @Light3 谢谢啦老哥,已经解决啦~~
    jianzhiyao020
        3
    jianzhiyao020  
       May 10, 2017
    JS 获取 JSON 的话,
    对象是无法保证顺序,
    叫后端转换成数组。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2934 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:19 · PVG 13:19 · LAX 22:19 · JFK 01:19
    ♥ Do have faith in what you're doing.