Welcome Guest, Not a member yet? Register   Sign In
Echoing results from a database
#7

[eluser]mdcode[/eluser]
Nothing has changed bar what's already been suggested... but here's a refresher:

Controller:
Code:
class Home extends Controller {

    function __construct()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->model('home_model');
        $data['siteTitle'] = $this->home_model->get_settings();
        $data['intro'] = $this->home_model->get_messages();
        $this->load->view('home_view', $data);
    }
}

/* End of file */
/* Location: controllers/home.php */

View:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;

&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?php echo $siteTitle; ?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<span class="fontTitle">Welcome to the &lt;?php echo $siteTitle; ?&gt;</span>
<span class="fontNormal">&lt;?php echo $intro; ?&gt;</span>

&lt;/body&gt;

&lt;/html&gt;

And the modified model using previous suggestions (just in case it's relevant):
Code:
class home_model extends Model {

    function __construct()
    {
        parent::Model();
    }
    
    function get_settings()
    {
    $this->db->select('siteTitle');
    $setquery = $this->db->get('settings');
        foreach ($setquery->result() as $row)
        {
           echo $row->siteTitle;
        }
    return $setquery;
    }
        
    function get_messages()
    {
    $this->db->select('intro');
    $msgquery = $this->db->get('messages');
        foreach ($msgquery->result() as $row)
        {
           echo $row->intro;
        }
    return $msgquery;
    }
    
}

/* End of file */
/* Location: models/home_model.php */


Messages In This Thread
Echoing results from a database - by El Forum - 03-10-2009, 11:15 PM
Echoing results from a database - by El Forum - 03-10-2009, 11:22 PM
Echoing results from a database - by El Forum - 03-11-2009, 03:15 PM
Echoing results from a database - by El Forum - 03-11-2009, 03:42 PM
Echoing results from a database - by El Forum - 03-11-2009, 04:07 PM
Echoing results from a database - by El Forum - 03-11-2009, 04:21 PM
Echoing results from a database - by El Forum - 03-11-2009, 04:25 PM
Echoing results from a database - by El Forum - 03-11-2009, 04:54 PM
Echoing results from a database - by El Forum - 03-11-2009, 05:07 PM
Echoing results from a database - by El Forum - 03-11-2009, 05:16 PM
Echoing results from a database - by El Forum - 03-11-2009, 05:22 PM
Echoing results from a database - by El Forum - 03-11-2009, 05:26 PM
Echoing results from a database - by El Forum - 03-11-2009, 05:32 PM
Echoing results from a database - by El Forum - 03-11-2009, 05:34 PM
Echoing results from a database - by El Forum - 03-11-2009, 05:43 PM
Echoing results from a database - by El Forum - 03-11-2009, 05:49 PM
Echoing results from a database - by El Forum - 03-11-2009, 06:06 PM
Echoing results from a database - by El Forum - 03-11-2009, 06:07 PM
Echoing results from a database - by El Forum - 03-11-2009, 06:11 PM
Echoing results from a database - by El Forum - 03-11-2009, 06:17 PM
Echoing results from a database - by El Forum - 03-11-2009, 06:55 PM
Echoing results from a database - by El Forum - 03-11-2009, 07:02 PM
Echoing results from a database - by El Forum - 03-11-2009, 07:05 PM
Echoing results from a database - by El Forum - 03-11-2009, 07:27 PM
Echoing results from a database - by El Forum - 03-11-2009, 07:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB