PHP / mySQL产品系统(非常一般)

时间:2011-12-22 15:31:30

标签: php product

我正在设计一个非常通用的PHP产品系统,因为每个产品可能有很多选项(“高度”,“宽度”,“颜色”,“性别”等)但是某些产品可能没有这些选项,有些可能没有。

例如,抽屉柜可能具有“尺寸”(由网站用户设置的适当尺寸列表),“抛光”(是/否)和“涂漆”(是/否)。然而,新电视可能根本没有选择。

任何人都可以为用户推荐一种方法来设置他们的产品所需的选项(例如,“抛光”对于零售电器来说根本不相关)然后将各种选项组合的价格存储为他们为每种产品指定了什么?

2 个答案:

答案 0 :(得分:0)

IMO,这是一个非常普遍的问题,您需要提供有关细节的更多信息。

我脑海中浮现的一个解决方案如下

public class myAwesomeClass {

$typeOfMyClass; //got from a DB when a user creates a new type.
$keyAndValuePair; //holds the key=>value pair of the type's data

}

并在外界访问它。

$obj = new myAwesomeClass();
//based on $obj->typeOfMyClass value process
foreach ($obj->keyValuePair as $key=>$value) {

//perform your operations

}

答案 1 :(得分:0)

`options` text null,

 //DONT run this directly, it needs escaping...but you get the idea.
 insert into tablename values({['polished':(int)1, 'size':'oh_its_big']}), ({['color':'hotpink']});


//run your query
$query = $db->select("* from tablename");

//loop query, json_decode the options string and assign to array
foreach($query as $q)
{
   $tmp[] = (array)json_decode($q->options);
   foreach($tmp as $options)
   {
       //run some conditional statements
       if(array_key_exists('size', $options))
       {
            //do something
       }
   }
}