dongzhe6287 2014-11-26 14:13
浏览 40
已采纳

使用php在MYSQL中根据用户输入检索列名

Currently i am doing a PHP GET and getting values after clicking the submit button.

I got the values out from the submit button but I dont know how to reference them to the values in column.

For example, after clicking the submit button, I get the value 1.

Inside my database i have 3 columns

Col 1 Col 2 Col 3

 2   3  1

How do i get the COLUMN name by just having the value itself? Thank you so much!

  • 写回答

2条回答 默认 最新

  • duanpo2813 2014-11-26 14:29
    关注

    Ugly/silly, but would do what you want:

    Query:

    SELECT * FROM yourtable WHERE 1 in (col1, col2, col3, ... ,colN)
    

    and then manually pick out the value in client code:

    $row = mysql_fetch_assoc($result);
    $matches = array_search(1, $row);
    var_dump($matches);
    

    You can't get away from listing all of the columns in the query, because there's no WHERE x IN (*)-type construct.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)