我需要帮助这个选择wordpress数据库中的类:
我想要实现的是显示前6个新人的帖子/记录。
图像的路径,图像名称,属性标题,属性功能(有多少卧室和浴室等)房产价格和房产价格单位(如果是$或丹麦克朗等)
在这个链接All properties在这里你可以看到我想在我的头版上实现,只是没有谷歌地图和排序列表,只有6个第一篇文章:All properties
这是表:wp_wpl_properties,wp_wpl_units,wp_wpl_items来实现我的目标所以我试图做出这个选择查询:
在此处输入代码
<?php
global $wpdb;
$results = $wpdb->get_results
("SELECT * FROM wp_wpl_properties,wp_wpl_units,wp_wpl_items
where wp_wpl_properties.price_unit= wp_wpl_units.id and wp_wpl_properties.id= wp_wpl_items.parent_id LIMIT 6;");
foreach ( $results as $result ) {
?>
我已将表格文件附加到此问题,此处:
我所制作的代码没有任何错误。
我的问题是,我在第一列显示相同的记录3次,在接下来的3列显示相同的记录,希望这样做感觉:)
这是我的首页的链接:My frontpage
你想要这样吗?
$results = $wpdb->get_results ("
SELECT * FROM wp_wpl_properties
join wp_wpl_units on wp_wpl_properties.living_area_unit= wp_wpl_units.id
join wp_wpl_properties on wp_wpl_properties.id= wp_wpl_items.parent_id LIMIT 6");
要么
$results = $wpdb->get_results ("
SELECT * FROM wp_wpl_properties
join wp_wpl_units on wp_wpl_properties.living_area_unit= wp_wpl_units.id
join wp_wpl_properties on wp_wpl_properties.id= wp_wpl_items.parent_id
where wp_wpl_properties.id= 1");
$results = $wpdb->get_results
("SELECT * FROM wp_wpl_properties
Inner Join wp_wpl_units ON wp_wpl_properties.living_area_unit = wp_wpl_units.id
Inner Join wp_wpl_items ON wp_wpl_properties.id= wp_wpl_items.parent_id
LIMIT 6;");
在你的MySQL查询中,
SELECT * FROM wp_wpl_properties,
wp_wpl_units,
wp_wpl_items
where wp_wpl_properties.price_unit=wp_wpl_units.id
and wp_wpl_properties.id= wp_wpl_items.parent_id
LIMIT 6
MySQL以不同方式单独检查三列中的每一列,并为它们生成输出,即使它们是相同的。
执行内部联接而不是单独检查三列将是解决方案。喜欢,
SELECT DISTINCT * FROM wp_wpl_properties as props
Inner Join wp_wpl_items as items ON items.parent_id = props.id
Inner Join wp_wpl_units as units ON units.id = props.living_area_unit
LIMIT 6
而不是select distinct * from
,只获得你需要的列。它会在很大程度上加快查询速度!像SELECT DISTINCT props.ID, items.ID FROM ...
。
希望这可以帮助。