Select query's order not working in prepared statement

前端 未结 2 756
野的像风
野的像风 2021-01-23 06:11

I am created a prepared select query and it appears the query is not picking up the DESC or I have the bind_param structured wrong. I am trying to get

相关标签:
2条回答
  • 2021-01-23 06:17

    Why you have put ? after "order by" statement?

    Your order by should reference to either id of your "profile_img" table or any timestamp field in that table...

    e.g. $sql = " SELECT * FROM profile_img WHERE user_id = ? ORDER BY id DESC LIMIT 1 ";

    here replace id (i am assuming this name) with the primary key field name of profile_image table

    or

        $sql = "
     SELECT *
     FROM profile_img
     WHERE user_id = ?
     ORDER BY created_on DESC LIMIT 1
    ";
    

    here created_on (which i have also assumed) can be replaced by any timestamp field if you any in profile_img table

    0 讨论(0)
  • 2021-01-23 06:26

    I don't think you can :

    • Use placeholders in an order by clause
    • Bind column names : you can only bind values -- or variables, and have their value injected in the prepared statement.

    You can use number instead of field name in the 'order by' clause

    0 讨论(0)
提交回复
热议问题