3

I have done my research and cannot find an answer so now I'm here to seek out professionals' advice.

I have a query which returns an array in model:

$sql = "SalesList ";
$sql = $sql."'".$current_company_code."', ";  
$sql = $sql."'".trim($current_user_id)."', "; 
$sql = $sql."'".$as_date."', ";  
$sql = $sql.$language_no; 

$DB=$this->load->database($current_database,TRUE);
$query = $DB->query($sql); 

return $query->result();

In controller: I passed the result to $data['sales_list'] and load to view

$data['sales_list'] = $this->SalesList->GetSalesList($current_database,$current_company_code,$current_user_id,date('Y-m-d 23:59:59'),$language_no);
$this->load->view('Sales_Record', $data);

In view:

  <?php foreach ($sales_list as $record): ?>
         <input type="hidden" name="sp_name_d[]" id="sp_name_d[]" value="<?php echo set_value('sp_name_d[]',trim($record->sp_name));?>"/>                      
   <?php endforeach; ?>

Problem: Upon submit, the same coding (which presents no issue on first load) prompted the following error:

A PHP Error was encountered
Severity: Notice

Message: Array to string conversion

Line Number: 39

Array"/>

Line no 39 refers to:

<input type="hidden" name="sp_name_d[]" id="sp_name_d[]" value="<?php echo set_value('sp_name_d[]',trim($record->sp_name));?>"/>  

Help needed. Thank you. Sincerely, blossoming programmer.

[Update] Cause of issue (Rookie mistake): I have some codes in view that use index in set_value (for radio button reference) which leads to multidimensional array:

<input type="radio" name="status_d[<?php  echo $counter;?>]" id="status_d[]" value="1" <?php echo set_value('status_d['.$counter.']', '1', $record->status==1); ?> checked />

Solution: in view added index in set_value:

<input type="hidden" name="sp_name_d[]" id="sp_name_d[]" value="<?php echo set_value('sp_name_d['.$counter.']',trim($record->sp_name));?>"/>  
Jess
  • 33
  • 4

1 Answers1

1

The Problem is: set_value() - The first time there is no input so it becomes an empty string, but after submit it is an array which remains array.

On an Fresh load of a page there is no previous input data, So everything is empty in Form When setting via set_value.