duanping2809 2013-04-02 16:06
浏览 258

从mysql获取第二行的输出

hi i have this mysql statement without limit so it will get first row in ascending order but i want to get the title of second row as well

    $res = mysql_query("select * from tas where id='{$m_id}' ");

after that i can fetch and get the first output without any issue earlier i was required to get the id so i used this

   $nidf=$m_id-1;

but now i need title of previous id.table consists if id,title,views etc .i know it can be done easily by this query

    $res2 = mysql_query("select * from tas where id='{$nidf}' ");

but i dont want to execute second syl query and i want to learn how it can be done without using above query

i cant not use while as i need only second title and rest of the thigs i need for first row only

  • 写回答

1条回答 默认 最新

  • duansen6750 2013-04-02 16:08
    关注
    SELECT *
    FROM tas
    WHERE id <= $m_id
    ORDER BY id DESC
    LIMIT 2
    

    fetch all the rows that have your specified ID OR* LESS, order by that id in descending order, then return only the first 2 rows in that ordered set. That'll be the $m_id you wanted, and the next immediately lower id as well.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统