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 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥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 图论 物流运输优化