Example query (Userid,name,sex is a database field for the user table)
Public Function Testa () {
$this->load->database ();
$query = $this->db->query (' SELECT * from user ');
foreach ($query->result () as $row)
{
Echo $row->userid;
Echo $row->name;
Echo $row->sex;
}
}
Example Insert (Userid,name,sex is a database field for the user table)
Public Function Testb () {
$this->load->database ();
$data = Array (' userid ' = ' + ', ' name ' = ' lisi ', ' sex ' = ' 1 ');
echo $str = $this->db->insert (' user ', $data);
}
Example Update (Userid,name,sex is a database field for the user table)
Public Function Testc () {
$this->load->database ();
$data = Array (' userid ' = ' + ', ' name ' = ' lisi ', ' sex ' = ' 1 ');
$this->db->where (' userid ', 1);
$this->db->update (' user ', $data);
}
Delete (Userid,name,sex for example)
Public Function testd () {
$this->load->database ();
$data = Array (' userid ' = ' + ', ' name ' = ' lisi ', ' sex ' = ' 1 ');
$this->db->where (' userid ', 22);
$this->db->delete (' user ', $data);
}
CI View load Display variables
Public Function Index ()
{
$this->load->library (' parser ');
$data = Array (
' Blog_title ' = ' My blog title ',
' blog_heading ' = ' My blog heading ',
' Blog_entries ' = Array (
Array (' title ' = ' Title 1 ', ' body ' = ' body 1 '),
Array (' title ' = ' Title 2 ', ' body ' = ' body 2 '),
Array (' title ' = ' Title 3 ', ' body ' = ' body 3 '),
Array (' title ' = ' Title 4 ', ' body ' = ' body 4 '),
Array (' title ' = ' title 5 ', ' body ' = ' body 5 ')
)
);
$this->parser->parse (' Welcome_message ', $data);
$this->load->view (' welcome_message ');
}
welcome_message.php
<title>{blog_title}</title>
<body>
{Blog_entries}
</body>
Attention:
In the use of <? Echo Base_url ();? > Before
First set
Config/autoload.php in the
$autoload[‘helper‘] = array(‘url‘, ‘form‘);
This article is from the "Wang Nimei Adult Road" blog, so be sure to keep this source http://8335914.blog.51cto.com/8325914/1435432