我想从模型控制器调用make_id,但每次我只是得到非法字符串,请帮助我这个,我做错了什么?从模型foreach返回警告:非法字符串偏移'model_id'
代码:
$this->load->model('catalog/models');
$data['models'] = array();
$results = $this->model_catalog_models->getTotalModelsByMark($mark_info['mark_id']);
foreach ($results as $result) {
$data['models'][] = array(
'model_id' => $result['model_id'],
'name' => $result['name'],
'mark_id' => $result['mark_id'],
'status' => $result['status'],
'category' => $result['category'],
'edit' => $this->url->link('catalog/models/edit', 'token=' . $this->session->data['token'] . '&model_id=' . $result['model_id'] . $url, true)
);
}
从视图代码:
public function getTotalModelsByMark($mark_id) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "models WHERE mark_id = '" . (int)$mark_id . "'");
return $query->row;
}
从控制器代码
<?php if ($models) { ?>
<?php foreach ($models as $model) { ?>
<tr>
<td class="text-center"><?php if (in_array($model['model_id'], $selected)) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $model['model_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $model['model_id']; ?>" />
<?php } ?></td>
<td class="text-left"><?php echo $model['name']; ?></td>
<td class="text-left"><?php echo $model['mark_id']; ?></td>
<td class="text-right"><?php echo $model['status']; ?></td>
<td class="text-right"><?php echo $model['category']; ?></td>
<td class="text-right"><a href="<?php echo $model['edit']; ?>" data-toggle="tooltip" title="<?php echo $button_edit; ?>" class="btn btn-primary"><i class="fa fa-pencil"></i></a></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="4"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
如果没有结果我得到没有$ text_no_results错误,但是当我有记录显示我得到非法字符串偏移量'model_id''name''mark_id''status''category,'fro米今天早上我试图得到这个修复,但我不能,这是开放购物车。
什么是你的表名? – Rashid
在db_models我有model_id,mark_id,名称,状态,类别,图像和我得到非法字符串的所有错误 – rpV
如果我尝试获取所有模型,它工作正常,但如果我想调用模型从一个特定的mark_id ,我得到非法的字符串错误 – rpV