我在弄清楚如何组合这两个查询时遇到了一些麻烦。
$get_id = $psk->goqueryvalue("SELECT `categoryid` FROM `products` WHERE `seo_title` = '{$url_title}'");
$get_category = $psk->goqueryvalue("SELECT `title` FROM `categories` WHERE `id` = '{$get_id}'");
($ psk-> goqueryvalue只返回一个值。)
由于
答案 0 :(得分:3)
SELECT c.title # also c.id if you need it
FROM categories c, products p
WHERE c.id = p.categoryid
AND p.seo_title = '{$url_title}'
答案 1 :(得分:1)
尝试类似
的内容 SELECT `categoryid`, `title` FROM `products`
LEFT JOIN `categories` ON `products`.`categoryid` = `categories`.`id`
WHERE `products`.`seo_title` = '{$url_title}'
答案 2 :(得分:1)
尝试类似
的内容$get_category = $psk->goqueryvalue("SELECT `title` FROM `categories` WHERE `id` = (SELECT `categoryid` FROM `products` WHERE `seo_title` = '{$url_title}'");
OR
$get_category = $psk->goqueryvalue("SELECT `title` FROM `categories` INNER JOIN `products` ON
`categories.id` = `products.categoryid` WHERE `seo_title` = '{$url_title}'");