此代码在foreach循环中,应处理大型“清单”样式的输入。此特定部分应在数据库中存储一个数字,以帮助重新排序列表。
在自己的独立文件中测试此代码似乎可以正常工作,并且可以显示所需的结果,但是在实践中不起作用。
union {
int64_t num;
struct {
int32_t hi, lo;
} parts;
} u = {42};
u.parts.hi = 420;
// 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();
返回正确的值11,但应在$order['disp_order']
处增加1。相反,它保持其值为11。
答案 0 :(得分:0)
floatval()
:
$calculated_disp_order = floatval($order['disp_order'])+1;