Welcome Guest, Not a member yet? Register   Sign In
Fatal Error: Call to undefined method CI_DB_mysql_driver::orderby() - HELP!
#1

[eluser]antoniog[/eluser]
I'm running the code that comes from the manual "Professional CodeIgniter" and arrived at this loading the page I get the following fatal error message:

Code:
Fatal error: Call to undefined method CI_DB_mysql_driver::orderby() in /home/youngtea/public_html/igniter/application/models/mproducts.php on line 32

Below is the code mproducts.php:

Code:
<?php
class MProducts extends CI_Model{

  function getProduct($id){
    $data = array();
    $options = array('id' => $id);
    $Q = $this->db->getwhere('products',$options,1);
    if ($Q->num_rows() > 0){
      $data = $Q->row_array();
    }
    $Q->free_result();
    return $data;
  }

  function getAllProducts(){
    $data = array();
    $Q = $this->db->get('products');
    if ($Q->num_rows() > 0){
      foreach ($Q->result_array() as $row) {
      $data[] = $row;
      }
    }
    $Q->free_result();
    return $data;
  }

   function getMainFeature(){
     $data = array();
     $this->db->select("id,name,shortdesc,image");
     $this->db->where('featured','true');
     $this->db->where('status','active');
     $this->db->orderby("rand()");
     $this->db->limit(1);
     $Q = $this->db->get('products');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data = array(
          "id" => $row['id'],
          "name" => $row['name'],
          "shortdesc" => $row['shortdesc'],
          "image" => $row['image']
          );
       }
    }
    $Q->free_result();
    return $data;

  }

  function getRandomProducts($limit,$skip){
$data = array();
$temp = array();
if ($limit == 0){
$limit=3;
}
$this->db->select("id,name,thumbnail,category_id");
$this->db->where('id !=', $skip);
$this->db->where('status', 'active');
$this->db->orderby("category_id","asc");
$this->db->limit(100);
$Q = $this->db->get('products');
if ($Q->num_rows() > 0){
  foreach ($Q->result_array() as $row){
         $temp[$row['category_id']] = array(
          "id" => $row['id'],
          "name" => $row['name'],
          "thumbnail" => $row['thumbnail']
          );
  }
}

shuffle($temp);
if (count($temp)){
  for ($i=1;$i<=$limit; $i++){
   $data[] = array_shift($temp);
  }
}
$Q->free_result();
return $data;
  }

}

/* End of file mproducts.php */
/* Location: ./application/models/mproducts.php */
?&gt;

This is the code on the manual and I tried for a wrong that does not exist for it.
I tried to remove the double quotes but the error is fatal!
There may be a name change of the method at this point I do not know?
The code was written for CodeIgniter 1.5., My version is 2.1.
Thank you all for your practical support.
#2

[eluser]InsiteFX[/eluser]
it's! This why you need to read the CodeIgniter Users Guide...
Code:
order_by
get_where
#3

[eluser]antoniog[/eluser]
[quote author="InsiteFX" date="1334912790"]it's! This why you need to read the CodeIgniter Users Guide...
Code:
order_by
get_where
[/quote]

Thank you very much.
In the User Guide i have found order_by(), then change to get_where().




Theme © iAndrew 2016 - Forum software by © MyBB