【问题标题】:Select where class from wordpress database:从 wordpress 数据库中选择 where 类:
【发布时间】:2018-03-19 11:46:09
【问题描述】:

我需要帮助才能从 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 ) {        


?>

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

wp_wpl_units.pdf

wp_wpl_items.pdf

wp_wpl_properties (1).sql

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

我的问题是我在第一列显示相同的记录 3 次,在接下来的 3 列显示相同的记录,希望这有意义:)

这是我首页的链接:My frontpage

【问题讨论】:

  • 您使用的是哪个主题? wp_wpl_properties这张桌子哪来的?
  • 我正在使用这个插件:WPL 是由 Realtyna 创建的专业 WordPress 房地产插件。其中 wp_wpl_properties 是这个主题的一部分:Real Estate Lite

标签: php mysql wordpress where-clause


【解决方案1】:

你想要这样吗?

$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");

【讨论】:

    【解决方案2】:
    $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;");
    

    【讨论】:

    • 虽然您的代码 sn-p 可能会解决问题,但您应该描述您的代码的目的是什么(它如何解决问题)。此外,您可能需要检查stackoverflow.com/help/how-to-answer
    • 我想要实现的是显示前6个新人帖子/记录以及图像的路径、图像名称、属性标题、属性特征(这是多少卧室和浴室等)房产价格和房产价格单位(如果是美元或丹麦克朗等)这些是表格:wp_wpl_properties、wp_wpl_units、wp_wpl_items 以实现我的目标,所以我尝试进行此选择查询:(“SELECT * FROM wp_wpl_properties, wp_wpl_units, wp_wpl_items where wp_wpl_properties .price_unit = wp_wpl_units.id 和 wp_wpl_properties.id = wp_wpl_items.parent_id LIMIT 6;");
    • 我尝试使用您的建议,但没有成功
    • 大家好,我试图删除这部分代码: Inner Join wp_wpl_items ON wp_wpl_properties.mls_id = wp_wpl_items.parent_id 现在一切正常,只是找不到图片的路径,看看这里: link
    • 请与数据共享您的完整表架构,我将确定哪个表必须使用图像字段名称
    【解决方案3】:

    在您的 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 ...

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 2014-09-08
      • 2016-12-04
      • 2013-09-15
      • 2015-12-06
      • 1970-01-01
      • 2014-02-14
      相关资源
      最近更新 更多