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