Welcome Guest, Not a member yet? Register   Sign In
MySql Query
#1

[eluser]epseix[/eluser]
Guys, I'm pretty new to this - HOW on earth do I run a MySql query between model, view and controller.

I can't see anything WRONG with what I have, but it just isn't working - in fact there's no error messages, just a blank page and absolutely NO source code when I look...

Controller:
Code:
<?php
class Test extends CI_Controller{

public function index(){
$this->load->model('Test_model');
$data['query'] = $this->Test_model->get_tq();
$this->load->view('test_view', $data);
}
}

Model:
Code:
<?php
class Test_model extends CI_Model{

    function __construct(){
        // Call the Model constructor
        parent::__construct();
    }

    function get_tq(){
  $sql = "SELECT * FROM myDb WHERE intId = ?";
  $query = $this->db->query($sql, array(3));
  return $query->result();
    }
}

View:
Code:
<html>
<head></head>
<body>
<?php
if($query->num_rows() > 0)
{
$row = $query->row();
echo $row->title;
}
?>
</body>
</html>

Just to point out, a foreach loop doesn't work in view file either...

Please help! I am losing my mind trying to figure it out!!!

Thanks in advance!
#2

[eluser]jairoh_[/eluser]
try
Code:
foreach ($query as $row)
{
    echo $row->title;
}




Theme © iAndrew 2016 - Forum software by © MyBB