Welcome Guest, Not a member yet? Register   Sign In
how to display single row result
#1
Bug 

Hi everbody

I want to send a single row from model to controller then from controller to view. i checked some of the same kind of question discussed earlier here but couldn't fix it

ERROR: Invalid argument supplied for foreach()

code for my controller is
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class HomeController extends CI_Controller
{
public function index()
{
$this->load->database();
$this->load->model('select');
$data['cat'] = $this->select->select();
$data['top'] = $this->select->topmenu();
$data['title'] = $this->select->get_title('categories');
$this->load->view('HomeView', $data);
}
}
?>
------------------------Select.php(Model)----
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<?php
class Select extends CI_Model
{
public function get_title($table,$where=NULL)
{
if(!empty($where))
{
$query = $this->db->get($table);
if($query->num_rows>0)
{
return $query->row();
}
else
{
return 0;
}}}}
------------------HomeView.php--------
<?php
foreach($title as $t)
{
echo $t->title;
}
?>


Messages In This Thread
how to display single row result - by nady - 09-07-2015, 08:13 AM
RE: how to display single row result - by Narf - 09-10-2015, 02:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB