Select query fetch_array expecting parameter

Hey,

I am trying to do a SELECT but it doesn’t seem to work.

This is my code:


<?php

class Items {
    protected $mysqli;

    public function __construct($host, $username, $password, $dbname) {
        $this->mysqli = new mysqli($host, $username, $password, $dbname);
        if ($this->mysqli->errno){
            echo 'Unable to connect'.$this->mysqli->error;
            exit();
        }
    }

    public function selectItemsByIDTest($ID) {
        $sql = 'SELECT *,i.ID as theID, i.name as theName
                FROM hussaini_items i
                LEFT JOIN hussaini_categories c on c.ID = i.CID
                WHERE i.deleted = 0 AND c.deleted=0
                AND i.ID = '.$ID;
        $result = $this->mysqli->query($sql) or die(mysql_error());
        return $result;
    }

    public function __destruct() {
        $this->mysqli->close();
    }
}

Then in my controller,


<?php
require_once('Models/Items.class.php');

$item = new Items('localhost', 'root', '', 'test');

    if(isset($_GET['ID'])){
    $result = $item->selectItemsByIDTest($_GET['ID']);
    $getItems = mysql_fetch_array($result);
    }
require_once('Views/add-new-item.phtml');

But i get this error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in G:\xampp\htdocs\Manstore\add-new-item.php on line 31

Line 31 is this:

$getItems= mysql_fetch_array($result);

I simply want to select lets say $getItems[‘name’] for e.g.

Why do i get this error? How can i fix this?

Thanks

the i in mysqli is important, because the mysqli and mysql extensions aren’t the same.

http://www.php.net/manual/en/mysqli-result.fetch-array.php

Hey,

I worked it out. I was missing an ‘i’ here:

$getItems = mysql_fetch_array($result);

I changed mysql to mysqli and i haven’t got any errors. So will see if i can pull anything out. :rolleyes: