I am getting error Illegal string offset 'order_status_id'
when I want to get loop data in view
Here's the code:
controller.php
if (isset($_POST["email"])) {
$email = $_POST["email"];
}
$this->load->model('order/myorder');
$data['data1'] = $this->model_order_myorder->getOrder($email) ;
view.php
foreach ($data1 as $row) {
echo echo $row->order_id;
}
model.php
class ModelOrderMyorder extends Model {
public function getOrder($email) {
$sql = "SELECT * FROM ".DB_PREFIX."order, ".DB_PREFIX."order_product WHERE ".DB_PREFIX."order.email = '$email'";
$query = $this->db->query($sql);
return $query ;
}
}
Still not getting it showing Trying to get property of non-object in view.
First off, if you want to iterate through all the order products for a given email (which is what I think you want) you should change the
getOrder()
method to return:Then in the controller you need to change:
to
Finally, in your view, you'll be accessing an array not an object so you should lose the extra
echo
(assuming this is a typo) and change:and get the index as:
Also, in addition to the above, I'll suggest you utilize some of the methods and code conventions found in Opencart:
When accessing the
$_POST
global you can use the sanitized version$this->request->post
Your query fails to backtick the order table which can result in errors in you didn't set a prefix. And you are not escaping
$email
which is a good idea for a number of reasons. Also, it makes things easy if you give your tables an alias. Finally, a join on the tables... so I might consider rewriting that query like this:To be honest, I'm not sure what results you're expecting from that query but bear in mind that if there are multiple products for an given order you will end up with multiple rows returned.
Just a few tips.. hopefully this is useful to you.