• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
To those array experts

#11
thanks to all!

I had been making way too complicated..

this woirked


Code:
if ($this->form_validation->run() == FALSE) {
// Bill Not Created
}else {
   $data['dates'] = array();
   $data['total'] = array();
   $data['total_cost'] = array();
   $data['total_for_cost'] = array();
$i=0;
while($i<$totalElements){
   $job_date = $job_dates[$i];
   $cust = $customer_ids[$i];

   $dates = new Bill_item();
   $dates->include_related('customer')->where('customer_id',$cust)->where('user_id', $uid)->where('item_date', $job_date)->order_by('customer_support_item', 'asc')->get();

  foreach($dates AS $date)
  {
    $data['dates'][$date->id] = array('cust' => $date->customer_id, 'item_date' => $date->item_date, 'item_hours' => $date->hours, 'item_amount' => $date->amount, 'cost' => ($date->amount*$date->hours), 'total_cost' => ($date->amount*$date->hours), 'jobs' => array('name' => $date->customer_support_item));
  }
  $i++;
  }
}
so i am quite embarassed i spent so long looking for a more difficult way of doing what turned out to be quite simple
Reply

#12
Hey, I'm glad you solved your problem! Smile

I know what you mean, and no need to be embarrassed. A lot of programming involves simplifying code that's too complex.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply

#13
It's really easy to get carried away and keep adding code to try to fix a problem, so I'm sure we've all been there a few times. I know that far too many of the times it has happened to me have resulted in me spending 12+ hours at work, followed by waking up after only 2 or 3 hours of sleep knowing that the whole thing will work if I just throw out everything I did in that 12+ hours and change 1 or 2 lines.

This is also why I will no longer work without a version control system (preferably Hg or Git, but anything will do in a pinch).
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.