首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从wordpress数据库中选择类的位置:

从wordpress数据库中选择类的位置:
EN

Stack Overflow用户
提问于 2018-03-19 19:46:10
回答 3查看 97关注 0票数 0

我需要帮助从wordpress数据库中选择where类:

我想要实现的是显示前6个新人的帖子/记录。

图像路径、图像名称、物业名称、物业特征(有多少间卧室和浴室等)、物业价格和物业价格单位(如果是$或丹麦克朗等)

在这里的链接All properties,你可以看到我想在我的首页上实现什么,只是没有谷歌地图和排序列表,只有6个第一篇文章:All properties

下面是表: wp_wpl_properties、wp_wpl_units、wp_wpl_items来实现我的目标,所以我尝试执行以下select查询:

在此处输入代码

代码语言:javascript
复制
<?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 ) {        


?>

我在这里附上了这个问题的表格文件:

wp_wpl_units.pdf

wp_wpl_items.pdf

wp_wpl_properties (1).sql

我写的代码没有任何错误。

我的问题是,相同的记录在第一列显示了3次,在接下来的3列也显示了3次,希望这能起到作用:)

这是我的首页链接:My frontpage

EN

回答 3

Stack Overflow用户

发布于 2018-03-19 20:38:33

你想要这样吗?

代码语言:javascript
复制
$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");

代码语言:javascript
复制
$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");
票数 0
EN

Stack Overflow用户

发布于 2018-03-19 20:47:46

代码语言:javascript
复制
$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;");
票数 0
EN

Stack Overflow用户

发布于 2018-03-20 03:22:55

在MySQL查询中,

代码语言:javascript
复制
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分别以不同的方式检查这三列中的每一列,并为所有列生成输出,即使它们是相同的。

执行内部连接而不是分别检查三列将是解决方案。喜欢,

代码语言:javascript
复制
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 ...

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49362202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档