Welcome Guest, Not a member yet? Register   Sign In
Errors
#1

[eluser]NateL[/eluser]
I'm reading Professional CodeIgniter and I'm having some issues with the first bit...I've already posted in the Wrox forum, but there's no activity and i doubt I will get an answer any time soon.

These are the two errors I encounter:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: id

Filename: controllers/welcome.php

Line Number: 13
Code:
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND `status` = 'active' ORDER BY `category_id` asc LIMIT 100' at line 4

SELECT `id`, `name`, `thumbnail`, `category_id` FROM (`products`) WHERE `id` != AND `status` = 'active' ORDER BY `category_id` asc LIMIT 100

These are some snippets of the code - which I think is exact..but who knows, could be a typo somewhere, I'm hoping.

Controller - welcome.php
Code:
class Welcome extends Controller {
function Welcome(){
        parent::Controller();    
    }
    
    function index(){
        $data["title"] = "Welcome to Claudia's Kids";
        $data["navlist"] = $this->MCats->getCategoriesNav();
        $data['mainf'] = $this->MProducts->getMainFeature();
        $skip = $data['mainf']['id'];
        $data['sidef'] = $this->MProducts->getRandomProducts(3,$skip);
        $data['main'] = 'home';
        $this->load->vars($data);
        $this->load->view('template');


    }
}

model - mproducts.php
Code:
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 getRandomProducts

It appears that 'id' is never called in from somewhere, which is resulting in both of these errors. I can see that my mysql query is messed up because it says != AND

I have many more files with a lot more code that I *think* is irrelevant to this issue. If it appears that i am missing something that could help you diagnose this problem, please let me know. Thanks!


Messages In This Thread
Errors - by El Forum - 09-19-2008, 08:41 AM
Errors - by El Forum - 09-19-2008, 08:49 AM
Errors - by El Forum - 09-19-2008, 08:52 AM
Errors - by El Forum - 09-19-2008, 09:47 AM
Errors - by El Forum - 09-19-2008, 10:11 AM
Errors - by El Forum - 09-19-2008, 10:12 AM
Errors - by El Forum - 09-19-2008, 01:15 PM
Errors - by El Forum - 09-19-2008, 01:48 PM
Errors - by El Forum - 09-19-2008, 03:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB