0

I face this error

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'company'

Filename: sales/print_file.php

In my Controller

$data=array("invoice_no"=>$invoice_no,
    "phone"=>$phone,
    "date"=>$date,
    "att"=>$Att,
    "company"=>$company,
    "area"=>$body,
    "subtotal"=>$subtotal,
    "tax"=>$tax,
    "total"=>$total,
    );

    .
    .
    $result=$this->other_tasks_model->inserts($data);
    .
    .
    $data["item1"] = $data;
    .
    .
    if($result==true)
        {
        $this->_tpl_super_admin('sales/print_file', $data);//for template changes based on user login
     }
     else{
     _error handling_
     }

In my model

public function inserts($data)
{
  $this->db->insert("invoice",$data);
  return $this->db->affected_rows() !=1 ? false:true;
}

In my view

  <?php 
    if(isset($item1)){
      foreach($item1 as $row){;
        echo "<h2>".$row['company']."</h2>";
        echo $row['date']."<br>"; 
        echo "#".$row['invoice_no'];
  ?>
Community
  • 1
  • 1
  • 1
    what line is the error on exactly? – Florian Humblot Jun 20 '17 at 07:46
  • Can you paste the full error, with its line reference and let us know which line it refers to? – Dan Walker Jun 20 '17 at 07:46
  • delete `foreach($item1 as $row){;` and change `$row` to `$item1` – Kazz Jun 20 '17 at 07:49
  • `Message: Illegal string offset 'area'` where is this code in your view?????? – LF00 Jun 20 '17 at 07:59
  • Possible duplicate of [Illegal string offset Warning PHP](https://stackoverflow.com/q/9869150/6521116) – LF00 Jun 20 '17 at 08:00
  • Please show all your data here, there must be some code cause this issue you didn't show it here. Refer to this [Illegal string offset Warning PHP](https://stackoverflow.com/q/9869150/6521116) – LF00 Jun 20 '17 at 08:02
  • Try this - `$viewData["item1"] = $data;` `$this->_tpl_super_admin('sales/print_file', $viewData);` – Bhaskar Jain Jun 20 '17 at 08:09
  • Sorry for the delay. here i have edited my question. @KrisRoofe Mr.@DanWalker is this edit clears now? What exactly I need to do is to Save the post values in db then display the post values in another view file(sales/print_file). – Praveen Ezlilan Jun 20 '17 at 08:26
  • Can your show the $data in your controller and view? – LF00 Jun 20 '17 at 08:29
  • @KrisRoofe The $data is initialised and assigning values in the controller as I typed above. $data=array("invoice_no"=>$invoice_no, ... In view I can't use the $data variable directly like foreach($data as $row). – Praveen Ezlilan Jun 20 '17 at 08:36
  • I mean pritn_r($data) to show the real value before and render the view. – LF00 Jun 20 '17 at 08:37
  • Sorry the print_r($data) said Undefined Variable error. but the print_r($item1) prints the values properly..@KrisRoofe – Praveen Ezlilan Jun 20 '17 at 08:40

1 Answers1

0
<?php 
  if(isset($item1)){
  foreach($item1 as $row){;
  echo "<h2>".$row['company']."</h2>";
  echo $row['date']."<br>"; 
  echo "#".$row['invoice_no'];
  ?>

as you have a 1 dimensional array

you do not require a foreach loop

either you do 2 thing

  • Remove the foreach part

    or

  • you modify $data being set to the view that way you can keep the foreach

loop

 $data[]= $data;(this will make it a 2 dimensional array)
$data["item1"] = $data;
.
Reuben Gomes
  • 878
  • 9
  • 16