CodeMama Posted March 2, 2009 Share Posted March 2, 2009 Hi all , I have two tables, and two queries, I need to use the results from the first query in the WHERE on the second query should I do this with a JOIN? Here is the code so far so you can see what I'm trying to do: $query = "SELECT `UserName`, `AdminID` FROM admin WHERE Key1 = 'YES' "; $result = mysql_query ($query) ; $row = mysql_fetch_assoc($result); //Reveal Variables for Debugging // include("VariableReveal2.php"); echo ("Hello <br>"); //echo $row['AdminID']; echo ($row); if ($row['Key1_PM'] == "NO") { header ("Location: Welcome.php?AdminID=$AdminID&msg=Sorry, you do not have access to that page."); } if (isset($_GET['SortBy'])) {$SortBy = $_GET['SortBy'];} else {$SortBy = 'WorkOrderID DESC';} if (isset($_GET['Page'])) {$Page = $_GET['Page'];} else {$Page = 1;} $PerPage = 30; $StartPage = ($Page - 1) * $PerPage; $sql= "SELECT * FROM workorders WHERE AdminID = '$row' "; // $sql .= "ORDER BY $SortBy LIMIT $StartPage, $PerPage"; $result = mysql_query ($sql); $row2 = mysql_fetch_assoc($result); $Total = ceil(mysql_num_rows($result)/$PerPage); So should I just join the tables I tried but got no results (prob got it wrong) and one other problem is that I am only returning 1 result yet I know there are others that meet the criteria of the first query. Thanks in Advance. Link to comment https://forums.phpfreaks.com/topic/147637-query-using-results-from-first-query-possible-right/ Share on other sites More sharing options...
trq Posted March 2, 2009 Share Posted March 2, 2009 should I do this with a JOIN? Yes. I tried but got no results Post your query in the mysql help forum. Link to comment https://forums.phpfreaks.com/topic/147637-query-using-results-from-first-query-possible-right/#findComment-775035 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.