OK, I have been having trouble for the week with this error, and what I've found i think i understand but when i change it it doesn't work. So if someone could help me understand a little better and tell me why this is not working.
The RunDown- I am trying to Display a list of the different Product families on my table.
Ok. So here is my Class
<?php
class mclean {
public $Product_id, $Catalog_Number, $Model_Code, $Caterogry, $Product_Family, $Product_Sub_Family, $Product_Name, $img;
function __construct($Caterogry){
// $db is defined in config.inc.php
global $db;
// sanitize input
$Caterogry = $db->real_escape_string($Caterogry);
// sql query
$sql = "SELECT * FROM Mclean_Products_info
WHERE Caterogry = '". $Caterogry . "'";
// if there is a result...
if($result = $db->query($sql)){
// $row contains an object
$row = $result->fetch_object();
// Set class attributes
$this->Product_id = htmlentities($row->Product_id);
$this->Catalog_Number = htmlentities($row->Catalog_Number);
$this->Model_Code = htmlentities($row->Model_Code);
$this->Caterogry = htmlentities($row->Caterogry);
$this->Product_Family = htmlentities($row->Product_Family);
$this->Product_Sub_Family = htmlentities($row->Product_Sub_Family);
$this->Product_Name = htmlentities($row->Product_Name);
$this->img = htmlentities($row->AllProductImages);
// Free result set
$result->close();
// if there are no results...
}else{
// there is probably an error
printf("Query failed: %s
", $db->error);
exit();
}
}
// Returns an array of all categories
public static function get_categories(){
//$db is defined in config.inc.php
global $db;
global $site_brand_ids;
//sql query
$sql = "SELECT DISTINCT product_family_id FROM mclean
LEFT JOIN product_families USING(product_family_id)
LEFT JOIN categories USING(category_id)
WHERE category_id = '91'";
//if there is a result
$categories = array();
if ($result = $db->query($sql)) {
while ($row = $result->fetch_object()){
$categories[] = new mclean($row->Caterogry);
}
//Free result set
$result->close();
}else{ // if there are no results
// There is a possible error
printf("Query failws: %s
", $db->error);
exit();
}
//return array
return $categories;
} //End of get_categories
}
?>
Now here is how i am calling it for the Display.
<?php
$categories = array('Accessories', 'Thermal Management', 'Busbar Systems');
$menu = array();
foreach($categories as $Caterogry){
$Caterogry = new mclean($Caterogry);
$menu[$Caterogry->Product_Family] = $Caterogry;
}
foreach($menu as $Caterogry => $Caterogry){
$Product_Family = $Caterogry->Product_Family;
$Product_Sub_Family = ($Caterogry->Product_Sub_Family);
echo '<div class="large-4 columns"><div class="product_category"><h4>' . $Product_Sub_Family . '</h4>';
$Product_Sub_Family= toAscii($Product_Sub_Family);
$category_link = $Product_Family;
$category_link = strtolower($category_link);
// $category_link = str_replace("-", "_", $category_link);
echo '<a href="/' . $category_link . '"><p>' . $Product_Sub_Family . '<span>Learn More »</span></p></a></div></div>';
// echo '<a href="/' . '_products/' . '"><p>' . $category_description . '<span>Learn More »</span></p></a></div></div>';
}
?>
Then I get This error on the page:
An error occurred in script '/websites/hoffmansales.local/views/mclean/content.php' on line 29: Trying to get property of non-object An error occurred in script '/websites/hoffmansales.local/views/mclean/content.php' on line 30: Trying to get property of non-object
Lines 29: and 30 is this:
$Product_Family = $Caterogry->Product_Family;
$Product_Sub_Family = ($Caterogry->Product_Sub_Family);
Any Help or guidance will be appreciated , I have also tried
var_dump($Product_Family);
var_dump($Caterogry->Product_Family);
exit();
and for some reason it brings back NULL? But why?