Odd one this. I have been working on this particular query for a few days now. The idea is to use the variables selected from first query to be used in second.
($project_id = $_GET['project_id'])|| ($project_id=$_POST['project_id']); $clients=$wpdb->get_results( " SELECT * FROM vo_wp_assigned_projects where project='$project_id'"); foreach($clients as $list){ $project=$list ->project; $client=$list ->client;//echo $client; $id=$list->client_id; echo $id; $name=$list->name; $users=$wpdb->get_results($wpdb->prepare( " SELECT * FROM vo_wp_clients where 'user_id'=%d", array( '$id'))); As a guide the echo $id; shows the variables but in the second query the 'where' element doesnt work, with all contents of table being displayed. I have looked at the wdp.prepare() on the Wordpress reference site. Any suggestions would be very helpful.
'$id'when you just want the value$id. I'm also not sure you need the array() around $id but it shouldn't matter.user_id in []outside the loop, although unhelpfully it looks like wpdb prepare() doesn't really support that. And actually you also don't want the inverted commas around user_id either in the SQL string: if you want to quote a column name in MySQL that's backticks not inverted commas, but you don't need to here.'$id'is not a variable, it's a string. E.g. the program$id = 'test'; echo '$id';prints$idnottest. It must be$idwithout the quotes. Also how are you testing that it does or doesn't work? Can you fix the indenting/formatting?