MySQL查询继续执行LIMIT 1

时间:2011-11-23 06:41:20

标签: php mysql

这里的查询应该是SELECT *页面,其中$ _GET ['variables']符合条件。 $_GET['variables'] are $page_type = type of page AND $loc = location to searchfunction SearchByTypeLoc($page_type, $loc) { $query = mysql_query(" SELECT `$page_type`.title AS title, `$page_type`.url_title AS url_title, `$page_type`.page_type AS page_type, `$page_type`.street AS street, `$page_type`.city AS city, `$page_type`.state AS state, `$page_type`.city_state_zip AS city_state_zip, `$page_type`.phone AS phone, LEFT(`$page_type`.body, 100) AS body, LEFT(`$page_type`.type, 50) AS type, GROUP_CONCAT( i.image_loc ) AS images FROM `$page_type` JOIN page_images i USING( title ) WHERE `$page_type`.page_type = '$page_type' AND `$page_type`.city = '$loc' ORDER BY title LIMIT 20"); while($fetch = mysql_fetch_assoc($query)) { ... ?> 。问题是我将它设置为LIMIT 20,但它只渲染一页。

{{1}}

知道如何让它不是LIMIT 1吗?

2 个答案:

答案 0 :(得分:1)

它不是LIMIT 1,但只有$page_type符合条件。您加入了title(为什么不加入ID?),因此只有一个$page_type的图片与title匹配。

如果您想要返回也可能没有任何图片的网页,则需要将JOIN更改为LEFT JOIN

将页面链接到图像的方式存在缺陷。如果更改页面标题,则需要记住并更新图像表中的相应标题。无论如何,这不是一个合适的外键。您应该在页面上使用auto_increment id。

答案 1 :(得分:1)

GROUP_CONCAT是一个聚合函数,
尝试明确添加

GROUP BY `$page_type`.title