Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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_Opencart - Fatal编程技术网

Php 如何连接MySQL表

Php 如何连接MySQL表,php,mysql,opencart,Php,Mysql,Opencart,我需要向查询中添加一个附加联接,但我不确定要在什么上联接它 SELECT DISTINCT * FROM {$this->prefix}category c LEFT JOIN {$this->prefix}category_description cd ON (c.category_id = cd.category_id) LEFT JOIN {$this->prefix}category_to_store c2s ON (c.ca

我需要向查询中添加一个附加联接,但我不确定要在什么上联接它

SELECT DISTINCT * FROM {$this->prefix}category c 
   LEFT JOIN {$this->prefix}category_description cd 
      ON (c.category_id = cd.category_id) 
   LEFT JOIN {$this->prefix}category_to_store c2s 
      ON (c.category_id = c2s.category_id) 
WHERE c.category_id = '" . (int)$category_id . "' 
   AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
   AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' 
   AND c.status = '1' 
我现在需要通过如下列值加入我的url\u别名表:

SELECT keyword FROM {$this->prefix}url_alias 
WHERE query = 'category_id=" . (int)$category_id . "'
--编辑以澄清--

这适用于OpenCart项目,该项目需要通过向现有类别/产品/制造商查询中添加关键字来简化url重写。

如何:

SELECT DISTINCT * FROM {$this->prefix}category c 
  LEFT JOIN {$this->prefix}category_description cd 
    ON (c.category_id = cd.category_id) 
  LEFT JOIN {$this->prefix}category_to_store c2s 
    ON (c.category_id = c2s.category_id) 

  LEFT JOIN {$this->prefix}url_alias u 
    ON u.query = CONCAT('category_id=', c.category_id)

WHERE c.category_id = '" . (int)$category_id . "' 
  AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
  AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' 
  AND c.status = '1' 
这个怎么样:

SELECT DISTINCT * FROM {$this->prefix}category c 
  LEFT JOIN {$this->prefix}category_description cd 
    ON (c.category_id = cd.category_id) 
  LEFT JOIN {$this->prefix}category_to_store c2s 
    ON (c.category_id = c2s.category_id) 

  LEFT JOIN {$this->prefix}url_alias u 
    ON u.query = CONCAT('category_id=', c.category_id)

WHERE c.category_id = '" . (int)$category_id . "' 
  AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' 
  AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' 
  AND c.status = '1' 

否表中没有类别_id的列。我应该说得更清楚些,我会修改这个问题。url_别名表中的列是
query
,该列中的行值是
category_id=12
product_id=345
等。好的,我编辑了答案,以便根据连接字符串进行连接测试。请注意,根据MySQL文档,很漂亮!康卡特我没想到,非常感谢彼得。非常好。不,表中没有类别id的列。我应该说得更清楚些,我会修改这个问题。url_别名表中的列是
query
,该列中的行值是
category_id=12
product_id=345
等。好的,我编辑了答案,以便根据连接字符串进行连接测试。请注意,根据MySQL文档,很漂亮!康卡特我没想到,非常感谢彼得。工作完美。