Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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 对此,什么是正确的SQL查询?_Php_Mysql - Fatal编程技术网

Php 对此,什么是正确的SQL查询?

Php 对此,什么是正确的SQL查询?,php,mysql,Php,Mysql,我有一个存储所有用户活动的表。我称之为带有字段的“会话”表: +--------------------------------------------------+ | id | content_type | content_id | action | +--------------------------------------------------+ 内容类型可以是1=视频、2=幻灯片、3=表格、4=调查、5=网站、6=互动 content\u id是实际内容的id。

我有一个存储所有用户活动的表。我称之为带有字段的“会话”表:

+--------------------------------------------------+
|  id   |  content_type  |  content_id  |  action  |
+--------------------------------------------------+
内容类型可以是1=视频、2=幻灯片、3=表格、4=调查、5=网站、6=互动

content\u id是实际内容的id。例如,我有“网站”表

在应用程序中,用户访问了google.com网站。“会话”表中存储的内容是:

+----------------------------------------------------------+
|  content_type  |  content_id  |          action          |
+----------------------------------------------------------+
|        5       |       3      |  Visited Google Website  |
+----------------------------------------------------------+
“网站”(或表单、视频等)表中的这些内容可以附加或标记到多个产品组

为此,我将其存储到名为“attached_product_groups”的表中

在该表中,我有以下字段:

+----------------------------------------------------+
|  content_type  |  content_id  |  product_group_id  |
+----------------------------------------------------+
例如,我必须将“产品组”表中的3个产品组附加到google.com网站:

“附件产品组”表将存储:

+----------------------------------------------------+
|  content_type  |  content_id  |  product_group_id  |
+----------------------------------------------------+
|       5        |      3       |         3          |
+----------------------------------------------------+
|       5        |      3       |         8          |
+----------------------------------------------------+
|       5        |      3       |         9          |
+----------------------------------------------------+
现在我的问题是,如何选择产品组中的所有“会话”日志

在我的应用程序中,我有一个产品组的下拉列表


非常感谢您帮助像我这样的初学者。:)

根据内容id显示网站的网站名称和产品是否可以在下面的查询中使用

从会话中选择sessions.content\u id、web.name、p.name 会议、网站、产品p、附加产品组pg在哪里 sessions.content\u id=web。id和p.id=pg.product\U group\U id


非常感谢您的回复,我要试试这个。:)
+----------------------------+
|  id  |        name         |
+----------------------------+
|  3   |  Mobile             |
+----------------------------+
|  8   |  Social Networking  |
+----------------------------+
|  9   |  Adsense            |
+----------------------------+
+----------------------------------------------------+
|  content_type  |  content_id  |  product_group_id  |
+----------------------------------------------------+
|       5        |      3       |         3          |
+----------------------------------------------------+
|       5        |      3       |         8          |
+----------------------------------------------------+
|       5        |      3       |         9          |
+----------------------------------------------------+