title: Passing variables from php to mysql query and displaying
body: <p>Can anyone tell me how to pass the php values $value_aid and $value_tradeid to my sql query res3 please ?</p>
  
  <pre><code>&lt;?php
  //error_reporting(E_ALL);
  
  ///////////////////////Connect to the database and close the connection when finished///////////////////////////////
  
  include ("dbconnect.php");
  
  ///////////////////////////////// Gather and Display area_id //////////////////////////////
  
  $res=mysql_query("SELECT area_id FROM pc_test WHERE postcodes = '".$_POST['postcode']."'");
  while ($row = mysql_fetch_array($res))
  {
  // This works !!
  //echo("$row[area_id]");
  $value_aid="$row[area_id]";
  echo("$value_aid");
  }
  
  ////////////////// Gather and Display postcodes relating to area_id ////////////////////////
  
  $res3=mysql_query("SELECT trade_id FROM trade WHERE trade_type = '".$_POST['trade_type']."'");
  while ($row3 = mysql_fetch_array($res3))
  {
  // And this works !!
  echo("\n$row3[trade_id]");
  $value_tradeid="$row3[trade_id]";
  }
  
  /**************************************** Gather the query information ********************************************/
  
  //************!!!!!!!!!!!!!!!!  This part does not work as the variable values are not being passed !!!!!!!!!!!**********//
  
  $res2=mysql_query("SELECT first_name, last_name, phone_mobile, postcode, trade_type FROM customer WHERE area_id = '$value_aid' &amp;&amp; trade_id = '$value_tradeid'");
  
  /**************************************** DISPLAY QUERY RESULTS HERE *********************************************/
  while ($row2 = mysql_fetch_array($res2))
  
  { 
  
  echo("&lt;TABLE align='center' border = '1' bgcolor = 'A7E3F6'&gt;&lt;TH&gt;&lt;strong&gt;SEARCH RESULTS&lt;strong&gt;&lt;/TH&gt;");
  echo("&lt;TR&gt;&lt;TD&gt;&lt;strong&gt;Name :&lt;strong&gt;\n$row2[first_name]\n$row2[last_name]&lt;/TD&gt;&lt;/TR&gt;");
  echo("&lt;TR&gt;&lt;TD&gt;&lt;strong&gt;Phone :&lt;strong&gt;\n$row2[phone_mobile]&lt;/TD&gt;&lt;/TR&gt;");
  echo("&lt;TR&gt;&lt;TD&gt;&lt;strong&gt;Postcode :&lt;strong&gt;\n$row2[postcode]&lt;/TD&gt;&lt;/TR&gt;");
  echo("&lt;TR&gt;&lt;TD&gt;&lt;strong&gt;Trade Type :&lt;strong&gt;\n$row2[trade_type]&lt;/TD&gt;&lt;/TR&gt;&lt;/TABLE&gt;");
  }
  
  /*********************** If no matching records in my table...DISPLAY MESSAGE HERE ******************************/
  
  if (mysql_num_rows($res2) == 0) {
  
  echo ("&lt;strong&gt;&lt;br&gt;&lt;br&gt;No one is advertising for this area just yet, sorry.&lt;br&gt;We will have tradesmen advertising here very soon.&lt;/strong&gt;");
  }
  
  //include ("db_close.php");
  
  ?&gt;
  </code></pre>