[eluser]vincej[/eluser]
HI CroxNix - Ok, I have been working on my model and have made a few changes. Firstly for the benefit of clarity I removed all the locations barr 1. Secondly I put specific 'names' into the CI form within the view. Thirdly I changed my model to reflect the changes in the form and I added a strtotime() so that the DB get UNIX date stamps. All the undeclared indexes are gone. also the POST array is now giving me all the dates from the from - all good. BUT, my update query is still not updating the DB. I think this is because with only a single pickup id ( puid ) it is trying to push 4 dates into a single row .. that isn't going to work, unless I perhaps missed something big. So ... maybe I should do an IMPLODE() on the POST array so can get them all on 1 row with 1 puid ? If I was successfull doing that then, I would not need GROUP_CONCAT() at the initial SELECT time. I would rather not do it as it could add more complexity ... but if needs must ..
I am really sorry to be a burden, but this has really befuddled me. anyway - here is my data"
POST:
Code:
Array ( [location] => Collingwood [Dates1] => Wed 31 Dec 1970 [Dates2] => Wed 31 Dec 1969 [Dates3] => Wed 31 Dec 1969 [Dates4] => Wed 31 Dec 1969 [locationid] => 4 [puid] => 4 [submit] => Save Changes )
View:
Code:
<?php
foreach ($pickupdates as $item) {
$theDates = explode(',', $item['TheDates']);
?>
<tr align="center">
<td width="100" align="center"><?php echo $item['locationid'];?></td>
<td width="100" align="center"><?php $data = array('name'=>'location', 'size'=>20,'value' => $item['location']); echo form_input($data); ?></td>
<td width="100"><?php $data = array('name'=> 'Dates1','size'=>15,'value' =>(strftime("%a %d %b %Y",$theDates[0]))); echo form_input($data); ?></td>
<td width="100"><?php $data = array('name'=> 'Dates2','size'=>15,'value' =>(strftime("%a %d %b %Y",$theDates[1]))); echo form_input($data); ?></td>
<td width="100"><?php $data = array('name'=>'Dates3','size'=>15,'value' => (strftime("%a %d %b %Y",$theDates[2]))); echo form_input($data); ?></td>
<td width="100"><?php $data = array('name'=>'Dates4','size'=>15,'value' => (strftime("%a %d %b %Y",$theDates[3]))); echo form_input($data); ?></td>
<td width="150"> <?php echo anchor('admin/pickup_detail/deletelocation/'. $item['location'], 'Delete');?></td>
</tr>
<?php ;} ?>
</table>
<?php
form_input($data);
echo form_hidden('locationid', $item['locationid']);
echo form_hidden('puid', $item['puid']);
echo "<div class=submitted>". form_submit('submit','Save Changes')."</div>";
echo form_close();
Model:
Code:
function Updatelocation(){
foreach( $_POST as $pickupid=>$location) {
$puid = $_POST['puid'];
$locationid = $_POST['locationid'];
$data = array(
'locationid' => db_clean($locationid),
'puid' => db_clean($_POST['puid']),
'dates' => db_clean(strtotime('Dates1')),
'dates' => db_clean(strtotime('Dates2')),
'dates' => db_clean(strtotime('Dates3')),
'dates' => db_clean(strtotime('Dates4'))
);
$this->db->where('locationid',$locationid);
$this->db->where('puid',$puid);
$this->db->update('pudates',$data);
$this->session->set_flashdata('message', 'Table Updated');
}
}