简体   繁体   English

PHP从一个表中获取ID,并从另一表中提取与这些ID相对应的数据

[英]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.

相关问题 如何从 table1 的 ID 中提取数据并通过 PHP 将其放入 table2 的 FOREIGN KEY - How to pull data from table1's ID and place it into table2's FOREIGN KEY via PHP Codeigniter联接将ID从一个表的ID更改为另一个表的ID - codeigniter join changing id from one table's id to another 如何将一张表的所有id插入另一张表 - How to insert all id's from one table to another table PHP MYSQL。 如何基于另一个表中的2个不同的ID从一个表中检索相同的数据 - PHP MYSQL. How to retrieve the same data from a table based on 2 different ID's in another table 在一列中存储来自另一个表的多个ID? - storing several ID's from another table in one column? 使用posgres和php从数据库中的一个表中获取不在另一个数据库中另一个表中的所有ID - Getting all id's from one table in database that aren't in another table in another database using posgres and php 从一张表中取出 id 并在同一时间插入 - Take id from one table and insert in another same time PHP:从一个 mysql 表中获取最后一行的 id 号,并使用它来更新另一个表的第一行中的字段 - PHP: Taking the last row's id number from one mysql table and using it to update a field in the first row of another table 从一个表访问ID并将其插入到另一个表-PHP - Accessing the ID from one table and inserting it into another table - PHP Laravel 从表中获取 id 并将它们插入到另一个表中 - Laravel Getting id's from a table and inserting them into another table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM