douhuangjian9627 2016-08-05 07:00
浏览 29
已采纳

不需要在php代码中将mysql中的0添加到int数据类型中

I am working on a project where I am using database driven dropdown lists on which i also add Other whose value is "0" with other values id coming from database. and these IDs are using as the value of the particular drop down list. Now problem is this, I am using int data type in the database table, And I does not select any value from the table for drop down list but it add 0 to the table. And I do not need to add 0 in the database table. I also used NULL as default value for the column but it stored the value as 0. Please solve my problem, How i will store the value so that the value will not zero when i does not select anything in the select box. Thank you..

  • 写回答

2条回答 默认 最新

  • douweng7233 2016-08-06 05:01
    关注

    I found the solution for my question as I put the data type as int but NULLABLE and in php code I check the condition as if the value if blank the post the NULL value else the value will be whatever posted.

    $insert_array['column_name']=$this->input->post('control_name')!==''?$this->input->post('control_name'):NULL;

    So it will insert the NULL value if I does not select any value from the drop down list. Thank You

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

报告相同问题?

悬赏问题

  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?