gummby8 Posted October 12, 2012 Share Posted October 12, 2012 Hello I am trying to setup a form of data filtering to display certain users I have 2 tables "Users" and "Assigned_rolls" What I would like to do is display usernames of all users that have role #1 1)So the query would first get all user IDs from the assigned_roles table that have role 1 2)Then pull the names of all the returned use IDs from the users table. 3)Then display the names on a webpage. I am trying to use $result = mysql_query("SELECT ID FROM roles_assigned WHERE role = '1'"); $result1 = mysql_query("SELECT name FROM user WHERE ID = $result "); If I change $result to a single user id that exists in sql, that users name is displayed properly. I don't know how to get the array that is created in the first query to be used as a searchable variable list in the second query so it will return any user id that had a role of 1 assigned to it in the first table. Obviously I am doing something wrong here. Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/269408-trying-to-filter-data-through-two-tables/ Share on other sites More sharing options...
Jessica Posted October 13, 2012 Share Posted October 13, 2012 Use a JOIN. SELECT columns FROM table1 INNER JOIN table2 ON table1.primary_key = table2.foreign_key WHERE table1.column = $val Link to comment https://forums.phpfreaks.com/topic/269408-trying-to-filter-data-through-two-tables/#findComment-1384908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.