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

 

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.