简体   繁体   English

使用从另一表获取的数组从一个表中进行SQL SELECT行

[英]SQL SELECT rows from one table using an array taken from another table

I need to do something like this: 我需要做这样的事情:

$user_id = (int) get_logged_in_userud();

**$thread_ids** = $wpdb->query( "SELECT thread_id FROM $tableName1 WHERE user_id = %s), $user_id);

$iterateRows = $wpdb->query( "SELECT thread_id FROM $tableName2 WHERE thread_id IN $s), **$thread_ids**);

I tried to grab it this way, but it returns an array in an array and each row is an associative array. 我试图用这种方式来抓取它,但是它在数组中返回一个数组,并且每一行都是一个关联数组。 Once I have this data I need to iterate through all the selected rows with something like a while loop. 获得这些数据后,我需要使用while循环对所有选定的行进行迭代。

I did try and do this on my own first, and came up with the below code. 我确实尝试自己进行此操作,并提出了以下代码。 But its not in a usable format. 但是它不是可用的格式。 I need to echo through each item like $row['col_name']; 我需要回显每个项目,例如$ row ['col_name'];。 for each column. 每列。 The goal is to list all messages that match a thread_id and user_id. 目的是列出所有与thread_id和user_id匹配的消息。

$grabThreadList = $wpdb->query( $wpdb->prepare("SELECT A.* FROM $recipientTableName WHERE A.thread_id IN (SELECT B.thread_id FROM $senderTableName WHERE B.thread_is = A.thread_id "));

    foreach ($grabThreadList as $key => $value){

    $implodeMe = implode(',,,few ', $value);

}

如果这是您要尝试执行的操作,则可以只使用SQL来执行此操作:

SELECT thread_id FROM $tableName2 WHERE thread_id IN (SELECT thread_id FROM $tableName1 WHERE user_id = %s)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用从另一个表中获取的条件选择一个表 - Select a table using criteria taken from another table SQL从一个表中选择不在另一个表中的项 - SQL select item from one table that is not in another MYSQL-如何从第一个表返回数组,并在一个查询中使用该数组从另一个表中选择? - MYSQL - How to return array from first table and select from another table using that array in one query? 如何使用SQL Select插入将行从一个表复制到另一个表 - How can i use SQL Select Insert to copy rows from one table to another SQL从一个表中选择项目,从另一个表中选择条件 - SQL select items from one table with conditions from another 使用另一个表上的WHERE子句从表中选择的SQL查询 - SQL Query to select from a table using a WHERE clause on another table 从一个表中选择结果,并为每一行从另一张表中选择具有相同ID的所有行 - Select results from one table and for each row select all rows that have the same id from another table SQL将行从一个表复制到另一个表,但只能复制一次 - SQL copy rows from one table to another but only once 从一个表中选择所有行,并为另一表中的每一行选择一个特定值 - Select all rows from one table and one specific value for each row from another table PHP / SQL:仅使用一个查询,如果两个表中都有数据,则从两个表中选择行;否则,仅从一个表中进行SELECT - PHP/SQL: Using only one query, SELECT rows from two tables if data is in both tables, or just SELECT from one table if not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM