[eluser]Unknown[/eluser]
Could some php/ codeigniter wizard assist a noob with this function? I have only been writing code for a couple of days and i am trying to update data in a database.
The below function loops through each database row getting a folder and filename and loads the corresponding xml file. It then pulls a value from the xml file and inserts it into the database. It is failing at the update with a 1064 db error.
I know it should probably be split up into a model and controller but I dont understand php / codeigniter enough to do that yet.
Code:
function index() {
// query database for the number of rows, use in the for loop
$this->db->from('lrhotel');
$query = $this->db->get();
$rowcount = $query->num_rows();
for ($i=0; $i<=$rowcount; $i++) {
$row = $query->row($i);
// Build path to xml file
$xmlfile = 'http://ukvg/hxml/' . $row->folder . '/' . $row->file;
//Load xml
$loadxml = simplexml_load_file($xmlfile);
//Hotel id is also the primary key in the db
$id = $loadxml->HotelID;
//This is the string to insert into db
$desc_to_store = $loadxml->Descriptions->Description->Value;
//Insert into db
$data = array('desc' => $desc_to_store);
$this->db->where('id', $id);
$this->db->update('lrhotel', $data);
}
}
If i swap this line:
Code:
$data = array('desc' => $desc_to_store);
With this line:
Code:
$data = array('desc' => "'$desc_to_store'");
It works, but when i query the data it is output enclosed in single quotes?
Thanks!