How to find data when a result set is in an array?

I want to find data via id, I have such an array

$result= Array ( [3] => 536371014 [38] => 1435902884 [53] => 100000224980743 ) 

User _id

  [3], [38], [53] 

on user tab

  user_id name 3 usii 38 test 53 test 2 

I want to find all the data through the user ID, how can I do this with the user ID of the result set, which is the index, I tried a lot, but did not get success, please help me do this, thanks for the ton in advance.

+6
source share
3 answers

Use foreach like this

 foreach($result as $val) { echo $val[$user_id]; } 
+6
source

Something like this should work (cruel pseudocode)

 in_list = implode(", ", array_keys($result)); $all_users = mysql.query("select * from user_table where user_id in (" . in_list . ");"; 

array_keys should provide you with an array of only used indexes (3, 38 and 53)
implode with "," since the glue should give you a string like "3, 38, 53" suitable for mysql state IN .

+3
source
 $user_ids = implode(",",array_keys($result)); $query = "SELECT * FROM usertable WHERE user_id IN (".$user_ids.")"; 
+2
source

Source: https://habr.com/ru/post/944418/


All Articles