Guest User

Untitled

a guest
Mar 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. class Portfolio_model extends CI_Model {
  2.  
  3. public function get_items() {
  4. $this->db->select('name, description, image');
  5. $this->db->order_by('date', 'DESC');
  6. $q = $this->db->get('tablename'); // your tablename here
  7. if ($q->num_rows() > 0) {
  8. return $q->result();
  9. } else {
  10. return null;
  11. }
  12. }
  13.  
  14. }
  15.  
  16. class Portfolio extends CI_Controller {
  17. public function index() {
  18. $this->load->helper('html');
  19. $this->load->model('portfolio_model');
  20. $data['items'] = $this->portfolio_model->get_items();
  21. $this->load->view('portfolio', $data);
  22. }
  23. }
  24.  
  25. if (!is_null($items)) {
  26. foreach ($items as $item) {
  27. echo $item->name . '<br>';
  28. echo $item->description . '<br>';
  29. echo 'Image src: ' . base_url() . $item->image . '<br>'; // might need slash after base_url, don't remember
  30. echo img($item->image);
  31. }
  32. } else {
  33. echo 'No items found!';
  34. }
Add Comment
Please, Sign In to add comment