Jump to content

Help with joining or getting my syntax right on this query of two tables


CodeMama

Recommended Posts

I need to use the results of one query in the WHERE parameters of another..JOIN?

 

$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);
    

     

Thanks in Advance

 

Not sure if this is what your after...

 

Just name each query with a different name and the rows consecutively

$query = (blablabla);

$row ['bla'];

//new query with 1st query results

$includes = $row ['bla'];
$query2 = (blablabla $includes);

$row2 ['blabla'];

Not sure if this is what your after...

 

Just name each query with a different name and the rows consecutively

$query = (blablabla);

$row ['bla'];

//new query with 1st query results

$includes = $row ['bla'];
$query2 = (blablabla $includes);

$row2 ['blabla'];

Um, no.

 

 

SELECT *
FROM admin AS a
INNER JOIN workorders USING ( AdminID )
WHERE a.Key1 =  'YES'

 

But I realy hope you're not doing all of that just for a count!

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.