I'd like to have some class that has hold all about item that want to be sell, there are many item such as design, product, default product etc. and all product wanted to be hold in one database, so i can easily has a connection to table images, one to many.
so I created a class that would be hold all data in the item table...
the class has to be know what kind of product it is.
but the problem is when a certain column is undefined in function, but it is defined in script.
here is the MySQL table...
create table item (
itemID int not null auto_increment,
itemDiscount int default 0,
orderCount int default 0,
itemName text,
designID int,
embedID int,
productID int,
defaultProductID int,
undesignID int,
.
.
-- constraint declaration
);
itemDiscountis for discount of productdesignIDis for description of the design (constraint withdesigntable)productIDis for the product from user and it already designed (constraint withproducttable)undesignIDis product from user but haven't designed (constraint withundesigntable)defaultProductIDis for product that has provided by the web. (constraint withdefaultPorducttable)embedIDis for embedding eitherdesignID+defaultProductIDordesignID+undesignIDthat has been organized inembedtable
I have inserted some data, here is the data (only for debugging purposes)
itemID ... designID productID defaultProductID undesignID embedID 1 1 2 1 3 1 4 1
class item{
public $type;
.
.
/**
* Determine what kind of product in certain row.
* @param array $row
* @return string
*/
static function itemType($row){
if(!is_null($row["productID"])){
return "product";
}else if(!is_null($row["defaultProductID"])){
return "default";
}else if(!is_null($row["designID"])){
return "design";
}else if(!is_null($row["embedID"])){
$query = "select * from embed where embedID={$row["embedID"]}";
$result = execute($query);
$row = mysqli_fetch_assoc($result);
return "embed_" . self::itemType($row);
}
}
function __construct(){
//do stuff
}
}
so i tried my static function :
$query = "select * from item";
$result = execute($query);
while($row = mysqli_fetch_assoc($result)){
echo item::itemType($row) . "<br/>";
//debug($row);
echo $row["defaultProductID"] . "<br/>";
}
And this is I got:
design default 1 product Notice: Undefined index: defaultProductID in C:\Users\jodi\Documents\Visual Studio 2013\Projects\Prodegitv2\Prodegitv2\includes\item.php on line 17 embed_design
Why I got that kind of notice?
1 is printed, so index defaultProductID has to be defined.
so I checked locals in debugging mode, here is the link for screenshot: http://postimg.org/image/ssfqv5f6h/
in visual studio debug mode, defaultProductID is defined...
Why does $row["defaultProductID"] be undefined in function??
is there any alternative solution??