I want update multiple data's from array with where condition (2 post value)
$markid=50008; (Post Item)
$ass='Att1';(Post Item)
$data=array( 'regno'=>$regno,'assmark'=>$assmark);
$query="update pre_marks set $ass=$assmark where regno=$regno and markid=$markid" ;
$this->db->query($query);
My output should be
Array
(
[regno] => 210417103001
[Att1] => 58
)
Array
(
[regno] => 210417103002
[Att1] => 23
)
Array
(
[regno] => 210417103003
[Att1] => 20
)
Array
(
[regno] => 210417103004
[Att1] => 45
)
Array
(
[regno] => 210417103005
[Att1] => 25
)
Array
(
[regno] => 210417103006
[Att1] => 0
)
This worked as well. But error comes
A Database Error Occurred Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where regno= and markid=50009' at line 1
update pre_marks set Att1= where regno= and markid=50009
Filename: C:/xampp/htdocs/Admin-Panel/system/database/DB_driver.php
Line Number: 691
How to solve this?
$markid = $this->input->post('markid');
$ass = $this->input->post('sel_ass1');
for($i=12;$i<=$i+6;$i++) {
$regno= $objWorksheet->getCellByColumnAndRow(2,$i)->getValue();
$assmark= $objWorksheet->getCellByColumnAndRow(5,$i)->getValue();
$data=array('regno'=>$regno,$ass=>$assmark);
echo '<pre>';
print_r($data);
echo '</pre>';
$this->db->where(['regno' => $regno,'markid' => $markid]);
$this->db->update('pre_marks',[$ass => $assmark]);
if ($this->db->affected_rows() > 0 ) {
return TRUE;
}
else {
return FALSE;
}
}