Php mysqli遇到非数字值
遇到非数字值 第51行是指这一行 它向我显示一个错误非数值Php mysqli遇到非数字值,php,mysqli,codeigniter-3,codeigniter-query-builder,codeigniter-database,Php,Mysqli,Codeigniter 3,Codeigniter Query Builder,Codeigniter Database,遇到非数字值 第51行是指这一行 它向我显示一个错误非数值 ->更新('purchase',数组('item_qty'=>'item_qty'+$item_qty)) 这不是javascript array('item_qty'=>'item_qty'+$item_qty) 如果您试图与+保持一致,则是。否则,添加字符串就没有多大意义。也许你想要这个 array('item_qty'=>'item_qty'.$item_qty) 带点 或者你只是需要它的价值 array('ite
->更新('purchase',数组('item_qty'=>'item_qty'+$item_qty))代码>
这不是javascript
array('item_qty'=>'item_qty'+$item_qty)
如果您试图与+
保持一致,则是。否则,添加字符串就没有多大意义。也许你想要这个
array('item_qty'=>'item_qty'.$item_qty)
带点
或者你只是需要它的价值
array('item_qty'=>$item_qty)
这更可能是因为PHP不关心变量类型,但数据库可能会显示,并且您的错误为非数值
,因此concat将始终为您提供一个类型为非数值的字符串。您正在执行字符串+数值而不是数学运算
正好在这一行->更新('purchase',array('item_qty'=>'item_qty'+$item_qty))代码>
这是因为您正在尝试获取字符串和数字的总和
将代码更改为
function upd_sales($upd_sales)
{
$item_name=$upd_sales['item_name'];
$item_qty=$upd_sales['item_qty'];
$this->db
->where('item_code', $item_name)
->update('purchase',array('item_qty'=> $item_qty));
}
试试这种方法,你需要在mysql中写一个更新项目数量的方法
function upd_sales($upd_sales)
{
$item_name=$upd_sales['item_name'];
$item_qty=$upd_sales['item_qty'];
$this->db->where('item_code', $item_name)
->set('item_qty', 'item_qty+'.$item_qty, FALSE);
->update('purchase');
}
案例$competitor1://竞争对手1获胜
$result=$resultwin1
$won1 = get_post_meta($competitor1, 'won', true);
update_post_meta($competitor1, 'won', $won1 + 1);
wps_update_history ( $competitor1, 'won', '', $lastIP );
update_post_meta($competitor1, 'lasttimestampbattle', current_time( "timestamp" ) );
$lost2 = get_post_meta($competitor2, 'lost', true);
update_post_meta($competitor2, 'lost', $lost2 + 1);
wps_update_history ( $competitor2, 'lost', '', $lastIP );
if ($haswon != "") {
// get actual post title
$postdata = get_post($competitor1);
if ( strlen ( $postdata->post_title ) > 0 )
$result = $postdata->post_title . " " . $haswon;
}
break;
'item\u qty'+$item\u qty
不是字符串连接,至少在PHP中不是这样,如果它的JavaScript作为PHP使用点
而不是+
,那就好了。他们所拥有的是向一个变量添加一个字符串,PHP可能对此没有问题,但在逻辑上没有意义,因为它会将sting视为0
+数字。array('item\u qty'=>'item\u qty.$item\u qty)
仍然是非数字的。
function upd_sales($upd_sales)
{
$item_name=$upd_sales['item_name'];
$item_qty=$upd_sales['item_qty'];
$this->db
->where('item_code', $item_name)
->update('purchase',array('item_qty'=> $item_qty));
}
function upd_sales($upd_sales)
{
$item_name=$upd_sales['item_name'];
$item_qty=$upd_sales['item_qty'];
$this->db->where('item_code', $item_name)
->set('item_qty', 'item_qty+'.$item_qty, FALSE);
->update('purchase');
}
$won1 = get_post_meta($competitor1, 'won', true);
update_post_meta($competitor1, 'won', $won1 + 1);
wps_update_history ( $competitor1, 'won', '', $lastIP );
update_post_meta($competitor1, 'lasttimestampbattle', current_time( "timestamp" ) );
$lost2 = get_post_meta($competitor2, 'lost', true);
update_post_meta($competitor2, 'lost', $lost2 + 1);
wps_update_history ( $competitor2, 'lost', '', $lastIP );
if ($haswon != "") {
// get actual post title
$postdata = get_post($competitor1);
if ( strlen ( $postdata->post_title ) > 0 )
$result = $postdata->post_title . " " . $haswon;
}
break;