php - 如何在不获取非法字符串偏移的情况下循环
问题描述
即使记录正确插入,我仍然收到此错误并且无法找到问题所在
INSERT INTO 都出现错误,但是当我检查数据库记录时是否存在并且它是正确的,那么如何处理这个错误?
这是我的代码和转储
$order_id = $this->db->getLastId();
if ($data['options'] != '') {
foreach ($data['options'] as $filter => $option) {
$check = $this->db->query("SELECT
oc_product_option.option_id,
oc_option.type,
oc_option_description.name,
oc_product_option_value.option_value_id,
oc_option_value_description.name AS option_name
FROM oc_product_option
LEFT JOIN oc_option ON (oc_product_option.option_id = oc_option.option_id)
LEFT JOIN oc_option_description ON (oc_product_option.option_id = oc_option_description.option_id)
LEFT JOIN oc_product_option_value ON (oc_product_option_value.product_option_value_id = '" . (int)$option . "')
LEFT JOIN oc_option_value_description ON (oc_option_value_description.option_value_id = oc_product_option_value.option_value_id)
WHERE oc_product_option.product_option_id = '" . (int)$filter . "'
AND oc_product_option.product_id = '" . (int)$data['product_id'] . "'");
foreach ($check->rows as $option_type) {
if ($option_type['type'] == 'custom') {
$this->db->query("INSERT INTO " . DB_PREFIX . "fast_order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$data['product_id'] . "', product_option_id = '" . (int)$filter . "', name = '" . $this->db->escape($option_type['name']) . "', value = '" . $this->db->escape($option) . "', type = '" . $this->db->escape($option['type']) . "'");
}else {
$this->db->query("INSERT INTO " . DB_PREFIX . "fast_order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$data['product_id'] . "', product_option_id = '" . (int)$filter . "', product_option_value_id = '" . $this->db->escape($option) . "', name = '" . $this->db->escape($option_type['name']) . "', value = '" . $this->db->escape($option_type['option_name']) . "', type = '" . $this->db->escape($option['type']) . "'");
}
}
}
}
$data['选项']
Array
(
[1330] => 1853
[1181] => 2
[1182] => 1
[1179] => 1660
)
$支票
stdClass Object
(
[num_rows] => 1
[row] => Array
(
[option_id] => 16
[type] => select
[name] => Двулицев Размер
[option_value_id] => 56
[option_name] => 300/100
)
[rows] => Array
(
[0] => Array
(
[option_id] => 16
[type] => select
[name] => Двулицев Размер
[option_value_id] => 56
[option_name] => 300/100
)
)
)
解决方案
type = '" . $this->db->escape($option['type']) . "'");
}
$option['type']
最后应该有$option_type['type']
-$option
来自您的外部 foreach 循环,并包含$data['options']
此时的整数之一。
推荐阅读
- html - 尝试以响应方式设置此按钮的样式
- ios - Web Socket Connection - iOS Swift 中的连接被拒绝/失败 - Starscream/RxStarscream
- javascript - React.createElement:类型无效 - Electron-React-Boilerplate
- compiler-construction - 使用实时变量分析计算工作清单
- algorithm - 实现 A* 算法的正确方法是什么?我们是否更新 closedSet 中的节点?
- r - 如何获得每n个值的移动平均值
- amazon-web-services - 带有 aws codeartifact 和 MVN 的 buildspec
- matlab - 图像处理中的信号转换
- r - 变量创建 - 推断年龄
- apache-spark - Spark RDD 分区效果