[英]PHP take id's from one table and pull data that corresponds with those id's from another table
I have this query: 我有这个查询:
$query = "SELECT *FROM wp_postmeta WHERE meta_key = '_isEvent' AND meta_value ='yes' ORDER BY post_id LIMIT 0, 5" or die(mysql_error());
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$eventid = $row ['post_id'];
echo "<p>".$eventid."</p>";
}
This currently posts some ids $eventid
. 目前,这会发布一些ID
$eventid
。 I now want to run another query in another table (same database) that pulls some post titles that matches those id's. 我现在想在另一个表(相同的数据库)中运行另一个查询,该查询提取一些与这些ID匹配的帖子标题。
Table is called "wp_posts" and column to match is "ID" and want to echo out post title from "post_title". 表称为“ wp_posts”,要匹配的列为“ ID”,并希望从“ post_title”中回显帖子标题。
Where do I start? 我从哪里开始?
Sounds like you want to use SQL joins. 听起来好像您想使用SQL连接。 W3 schools has a good intro article about this.
W3学校对此有很好的介绍性文章。 http://www.w3schools.com/sql/sql_join.asp
http://www.w3schools.com/sql/sql_join.asp
Something like the following 类似于以下内容
SELECT post_title FROM wp_postmeta m, wp_posts p WHERE m.wmeta_key = '_isEvent' AND m.meta_value ='yes' AND m.post_id == p.post_idORDER BY m.post_id LIMIT 0, 5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.