Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP中建模产品变体组合MYSQL表_Php_Mysql_Sql_Database_E Commerce - Fatal编程技术网

如何在PHP中建模产品变体组合MYSQL表

如何在PHP中建模产品变体组合MYSQL表,php,mysql,sql,database,e-commerce,Php,Mysql,Sql,Database,E Commerce,我创建了产品变体。我想插入mysql表。我需要创建一个表结构 在这段代码中,我得到了想要的输出。但是我想把它们保存在数据库里 示例代码 $data[]=array('small','medium','large'); $data[]=array('red','yellow'); $data[]=array(36, 37, 38); $combos = possible_combos($data); //calculate all the possible comobos creatable

我创建了产品变体。我想插入mysql表。我需要创建一个表结构

在这段代码中,我得到了想要的输出。但是我想把它们保存在数据库里

示例代码

$data[]=array('small','medium','large');
$data[]=array('red','yellow');
$data[]=array(36, 37, 38);

$combos = possible_combos($data);

//calculate all the possible comobos creatable from a given choices array
function possible_combos($groups, $prefix='') {
    $result = array();
    $group = array_shift($groups);
    foreach($group as $selected) {
        if($groups) {
            $result = array_merge($result, possible_combos($groups, $prefix . $selected. ' '));
        } else {
            $result[] = $prefix . $selected;
        }
    }
    return $result;
}

echo count($combos) . "\n";
print_r($combos);
示例输出

Array
(
    [0] => small red 36
    [1] => small red 37
    [2] => small red 38
    [3] => small yellow 36
    [4] => small yellow 37
    [5] => small yellow 38
    [6] => medium red 36
    [7] => medium red 37
    [8] => medium red 38
    [9] => medium yellow 36
    [10] => medium yellow 37
    [11] => medium yellow 38
    [12] => large red 36
    [13] => large red 37
    [14] => large red 38
    [15] => large yellow 36
    [16] => large yellow 37
    [17] => large yellow 38
)
我必须创建一个与此数组的组合,并将它们存储在表中。例如,他们都有自己的股票

示例表

 +---------------+     +-------------------+
 | PRODUCTS      |-----< PRODUCT_VARIANTS  |
 +---------------+     +-------------------+
 | #product_id   |     | #product_id       |
 |  product_name |     | #variant_id       |
 +---------------+     | #variant_name     |
                       +-------------------+
                              |
                           +--------^--------+
                        < VARIANT_VALUES  |
                        +-----------------+
                        | #product_id     |
                        | #variant_id     |
                        | #value_name   |
                        |       |
                        +--------v--------+
+-------------++-------------------+
|产品|------<产品||
+---------------+     +-------------------+
|#产品识别号| |#产品识别号|
|产品名称| |#变体(id)|
+---------------+|#变体_名称|
+-------------------+
|
+--------^--------+
如何创建表结构

多谢各位。
致以最诚挚的问候。

您具体要求什么?如何设置MySQL服务器?如何使用php从web服务器连接到它?如何创建表?如何在表中插入行?目前,这要么有点模糊,要么范围太广。一般来说,最好有一些您尝试过的代码,描述出哪里出了问题,需要发生什么,等等。然后我们可以帮助解决一个特定的问题,而不是一个抽象的问题。