php mysql向两个不添加数据类型,不需要在php代码中将mysql中的0添加到int数据类型中(Do not need to add 0 to int datatype in mysql fro...

不需要在php代码中将mysql中的0添加到int数据类型中(Do not need to add 0 to int datatype in mysql from php code)

我正在开发一个项目,我正在使用数据库驱动的下拉列表,我还添加了其他值为“0”的其他值来自数据库的ID。 并且这些ID用作特定下拉列表的值。 现在问题是这样,我在数据库表中使用int数据类型,并且我没有从表中选择任何值用于下拉列表但是它向表中添加0。 而且我不需要在数据库表中添加0。 我也使用NULL作为列的默认值,但它将值存储为0.请解决我的问题,我将如何存储值,以便当我没有在选择框中选择任何内容时值不会为零。 谢谢..

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..

原文:https://stackoverflow.com/questions/38783060

更新时间:2020-01-01 09:48

最满意答案

int类型默认始终为0。 如果你想留空(又名'')你可以使用char或varchar,text ... string types这可能会破坏你的服务器端程序,如果它期望int

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

2016-08-06

相关问答

int值可以是-2147483648这些是11位数,所以默认显示大小是11 unsigned int不允许负数,所以默认情况下只需要显示大小10 如下面的文档所示,存储SIGNED INT和UNSIGNED INT所需的位数相同,可存储数字的范围只是偏移: 无符号类型可用于仅允许列中的非负数,或者当需要较大的上限数值范围时。 例如,如果INT列为UNSIGNED,则列的范围大小相同,但其端点从-2147483648和2147483647更改为0和4294967295。 http://dev.mys

...

int类型默认始终为0。 如果你想留空(又名'')你可以使用char或varchar,text ... string types这可能会破坏你的服务器端程序,如果它期望int 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 va

...

你可以使用它在mysql中获取它。 SELECT TIMESTAMPDIFF(SECOND, column1, column2);

在PHP中获取它看到这个答案 在PHP中获取两次时间差 或者使用类似下面的内容,您可以使用从mysql获取的日期作为DateTime的字符串。 1 <?php

2

3 $time1 = new DateTime('13:00:59');

4 $time2 = new DateTime('19:01:00');

5 $interval = $time1->dif

...

time 0000-00-00超出了strtotime的范围,该范围以1901-12-13到2038-01-19为界。 它会返回破坏数据的下限。 这几乎适用于所有基于UNIX time_t的函数。 我的建议是在处理之前用NULL替换那些日期。 它们无效。 The time 0000-00-00 is outside the range of strtotime which is bounded by 1901-12-13 through 2038-01-19. It's returning the

...

如果需要根据列的名称使用不同的列类型,可以使用if / then或switch / case语句: for($i=0;$i

$f = strtolower(trim($data[$i]));

if ($f) {

// normalize the field name, strip to 20 chars if too long

$f = substr(preg_replace ('/[^0-9a-z]/',

...

这很简单,你可以简单地使用tinyint ,原因很简单,因为它只需要1个字节(-128到+127 / 0到255(无符号)) 旁注: 你可以避免另一个的原因是smallint需要2个字节而int占用4个字节,因为你只需要存储4个值,所以不需要浪费内存。 Thats simple you can simply take tinyint for the simple reason that it takes only 1 byte(-128 to +127 / 0 to 255 (unsigned))

...

这是因为数据类型限制。 数据类型INT的范围仅从-2147483648到2147483647 。 您可以使用数据类型BIGINT而不是。 但我认为,如果使用非常大的数字,最好的方法是使用文本数据类型(如VARCHAR )。 如果您需要数字进行计算,只需将其转换即可。 That's because of data type limit. The range of datatype INT only from -2147483648 to 2147483647. You can use datatyp

...

这是糟糕的设计,因为您需要搜索Ambience文件的特定值。 您可以使用FIND_IN_SET ,但查询速度很慢。 转向Ambience原子值 This is bad design as you need to search for specific values of Ambience filed. You can use FIND_IN_SET, but your query will be slow. Turn to atomic values for Ambience

TIMESTAMP是一个非常直接的选择。 它在内部实现为UNIX时间戳,但在外部它显示为日期字符串(例如“1970-01-01 00:00:01”)。 编辑:将INT迁移到时间戳,其中time_test是表, ts是原始列: ALTER TABLE time_test ADD ts_new TIMESTAMP;

UPDATE time_test SET ts_new = FROM_UNIXTIME(ts);

ALTER TABLE time_test DROP ts;

ALTER TABLE ti

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值