I'm just starting in CodeIgniter and can't get my data to display in the view. This to my (very limited) understanding should display the first, second and third columns of the table in the view but it returns Undefined variable: first. any help would be greatly appreciated thanks.
my model:
<?php class Model_model extends CI_model{
public function __construct() {
parent::__construct();
$this->load->database();
}
public function getData($string){
$sql = "SELECT first,second,third FROM Table WHERE first LIKE '%?%';";
$query = $this->db->query($sql,$string);
if ($query->num_rows() > 0) {
return $query;
}
my controller:
class User extends CI_Controller {
public function view($string) {
$this->load->model('Model_model');
$result = $this->Model_model-> getData($string);
echo $result->num_rows(); //returns correct number.
$this->load->view('view_display', $result);
}
}
my view:
...
// <table>
<tr><td>Poster:</td><td><?php echo $first; ?></td></tr>
<tr><td>Message:</td><td><?php echo $second; ?></td></tr>
<tr><td>Time posted:</td><td><?php echo $thrid; ?></td></tr>
// </table>
...