Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Portfolio_model extends CI_Model {
- public function get_items() {
- $this->db->select('name, description, image');
- $this->db->order_by('date', 'DESC');
- $q = $this->db->get('tablename'); // your tablename here
- if ($q->num_rows() > 0) {
- return $q->result();
- } else {
- return null;
- }
- }
- }
- class Portfolio extends CI_Controller {
- public function index() {
- $this->load->helper('html');
- $this->load->model('portfolio_model');
- $data['items'] = $this->portfolio_model->get_items();
- $this->load->view('portfolio', $data);
- }
- }
- if (!is_null($items)) {
- foreach ($items as $item) {
- echo $item->name . '<br>';
- echo $item->description . '<br>';
- echo 'Image src: ' . base_url() . $item->image . '<br>'; // might need slash after base_url, don't remember
- echo img($item->image);
- }
- } else {
- echo 'No items found!';
- }
Add Comment
Please, Sign In to add comment