douque2016 2019-02-19 10:19
浏览 32

为什么价值没有正确添加?

This code is in a foreach loop which should handle a large 'checklist' style input. This particular section should store a number in a database which helps re-order the list.

Testing this code in its own standalone file seems to work and shows the desired result, but put into practice it doesn't work.

// Get the number we need for the disp_order
$order_query = $db_connect->query("SELECT disp_order FROM procedure_data WHERE procedure_id = ".$pd_p_id." ORDER BY disp_order DESC LIMIT 1");
$order = $order_query->fetch_array(MYSQLI_ASSOC);

if ($order['disp_order'] == NULL) {
    $calculated_disp_order = 1;
} else {
    $calculated_disp_order = $order['disp_order']+1;
};

// Close this, we don't need it anymore
$order_query->close();

$stmt = $db_connect->prepare("INSERT INTO procedure_data VALUES 
(NULL, ?, ?, ?, ?, ?, ?, NOW())");
$stmt->bind_param("iissss", $pd_p_id, $calculated_disp_order, 
$pd_task, $pd_action_type, $pd_action, $pd_notes);
$stmt->execute();
$stmt->close();

$order['disp_order'] returns the correct value of 11, but should be increased by 1 at $calculated_disp_order = $order['disp_order']+1;. Instead it's keeping its value of 11.

  • 写回答

1条回答 默认 最新

  • doupao3662 2019-02-19 11:03
    关注

    floatval() was needed for the following line:

    $calculated_disp_order = floatval($order['disp_order'])+1;

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法