我试图从名为"post_id的数据库中获得一个属性值,以便在其他地方使用。
这是我的模型代码。$copy_query = "SELECT post_id FROM posts order by post_id DESC limit 1"; //query for selecting last post's post_id
$result = $this->db->query($copy_query); //adding that post_id to the $result variable
$sub_data = array(
'study_education_level' => $this->input->post('sub_education_level'),
'tourism_country' => $this->input->post('sub_tourism_country'),
'tourism_place_name' => $this->input->post('sub_tourism_placeName'),
'post_id' => $result
);
$this->db->insert('subcategories',$sub_data);
但是当我运行代码时,它会给我两个ERROR
遇到PHP错误
Severity: 4096 Message: Object of class CI_DB_mysql_result could not be converted to string Filename: mysql/mysql_driver.php Line Number: 553
和2.
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
INSERT INTO `subcategories` (`study_education_level`, `tourism_country`, `tourism_place_name`, `post_id`) VALUES ('Higher Study', '', '', )
Filename: C:'xampp'htdocs'learn'system'database'DB_driver.php
Line Number: 331
提前感谢!
顺便说一下,我已经解决了这个问题。
$result = $this->db->query($copy_query); //adding that post_id to the variable
if ($result->num_rows() > 0)
{
foreach ($result->result() as $row)
{
$post_id_plz = $row->post_id;
}
}