-1

how to post form and get posted data to controller and i don't know how to pass posted variable from controller to model after getting i want to pass variables to views

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
<?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 ;
    }

}

Regards Dev

jh314
  • 27,144
  • 16
  • 62
  • 82
rockie
  • 227
  • 1
  • 2
  • 8

1 Answers1

1

You simply pass the value as the parameter, e.g.

$this->model_shipping_order->getordertracking($_POST['email']) {

You should also escape the parameter in your query to prevent SQL injection e.g.

WHERE email = '" . $this->db->escape($email) . "' ");

rjdown
  • 9,162
  • 3
  • 32
  • 45
  • WHERE email = '" . $this->db->escape($email) . "' "); is not working actually when i get a single row it's working without errors but when i want get multiple value i kept in array it's not working – rockie Apr 11 '15 at 13:45
  • can you see this http://stackoverflow.com/questions/29578031/illegal-string-offset-order-status-id-in-opencart this coding not working i changed like that but still not working – rockie Apr 11 '15 at 13:47
  • So change your query to something more appropriate. Something like this http://stackoverflow.com/a/7029777/1301076 – rjdown Apr 11 '15 at 13:57
  • Please do not completely change the question after an answer has been posted. Just create a new one. – rjdown Apr 11 '15 at 14:07
  • i didn't change question i changed only code don't you see? – rockie Apr 11 '15 at 14:08
  • Yes, this is no longer related to "how to pass posted variable from controller to model". The question now seems to be "how do I rewrite my query to accept an array" – rjdown Apr 11 '15 at 14:10
  • it the same has before but i tried with different code it's not working for some variables – rockie Apr 11 '15 at 14:11
  • i for "order_id"=>$result["order_id"] having int datatype in database so its getting like that – rockie Apr 11 '15 at 14:11
  • can you see this question http://stackoverflow.com/questions/29578031/illegal-string-offset-order-status-id-in-opencart i tick your answer – rockie Apr 11 '15 at 14:14