如何将一个变量与另外两个变量(mysql)相关联?

时间:2015-01-04 10:38:42

标签: javascript php mysql ajax

我在mysql中有四个表(对象,类型,价格,日期)

所有这些都有两个颜色:" id "和" 变量"

例如:

Object table
+----+-----------+
| id | variable  |
+----+-----------+
|  1 | shop1     |
+----+-----------+
|  2 | shop2     |
+----+-----------+

type table
+----+----------+
| id | variable |
+----+----------+
|  1 | lemon    |
+----+----------+
|  2 | potato   |
+----+----------+

Date table
+----+------------+
| id | variable   |
+----+------------+
|  1 | 2014-10-11 |
+----+------------+
|  2 | 2014-12-11 |
+----+------------+


price table
+----+------------+
| id | variable   |
+----+------------+
|  1 | 5000       |
+----+------------+
|  2 | 2000       |
+----+------------+
|  3 | 4000       |
+----+------------+
|  4 | 3000       |
+----+------------+

我们在浏览器视图中真正需要的是:

Shop1:
+--------+------------+------------+
|        | 2014-10-11 | 2014-12-11 |
+--------+------------+------------+
| lemon  | 5000       | 3000       |
+--------+------------+------------+
| potato | 2000       | 4000       |
+--------+------------+------------+

价格是一个变量,可以像其他变量(日期,类型)一样改变,日期或类型的列可以更多 - (max - 5)

此表格看起来像Excel。但价格必须依赖于其他变量,因为其他对象可能使用相同的价格ID。

1 个答案:

答案 0 :(得分:-1)

首先通过类型表循环并获取ID

select * from type

Then Loop through ID's as $id

然后在循环中,您需要查询每个表中的每个所需值。例如

select variable  from price where ID = $id
select variable  from date where ID = $id