Jump to content

Query using results from first Query? Possible right?


CodeMama

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.