title: Select id from one query and use it in another
body: <p>I have this code. In the first query I want it to select a pid. Then I want to somehow use the selected pid as WHERE in the second query. This do not work but I want it to work on this(the same) page. I have read about this on other forums but I still didn't fix it. Probably a small mistake somewhere.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  ini_set('display_errors',1);
  error_reporting(E_ALL);
  
  if(mysqli_connect_errno())
  {
    echo mysqli_connect_error();
  }
  
  $loggedInUserId = $_SESSION['user_id'];
  $resu = mysql_query("SELECT pid FROM users WHERE id='$loggedInUserId';");
  $ro = mysql_fetch_row($resu);
  
  $sql= "SELECT pid, project_name, image, image_type FROM project WHERE pid ='". $row["pid"]. "';";
  
  $result = $mysqli-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      while($row = $result-&gt;fetch_array()) {
      
          //$type= "Content-type:".$row['image_type'];
      //header ($type);
      echo "&lt;form action='respodents.php' method='post'&gt;&lt;button name='submit' id='projectbutton'&gt;
              &lt;div&gt; 
                  &lt;img src=pic.php?pid=".$row['pid']." width=100px height=100px/&gt;"." &lt;div  id='project_name'&gt;".$row['project_name']."&lt;/div&gt;"."
         
              &lt;input type='hidden' name='pid' value='".$row['pid']."'&gt;
              &lt;input type='hidden' name='project_name' value='".$row['project_name']."'&gt;
              
              &lt;/div&gt;
         &lt;/button&gt;&lt;/form&gt;";
      }}
  
  mysqli_close($mysqli);
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>