title: Dynamic Data Display in form with PHP/MySQL
body: <p>Ok, in order to ask the question properly, I need to give a brief of what I am trying to achieve. So please bear with me.</p>
  
  <p>I have a form that shows a drop down menu which fetches data from MySQL database.</p>
  
  <p><a href="http://img690.imageshack.us/img690/5378/59790538.png" rel="nofollow noreferrer">drop dpwn menu that fetches mysql data http://img690.imageshack.us/img690/5378/59790538.png</a></p>
  
  <p>And my MySQL table looks like this:</p>
  
  <p><a href="http://img841.imageshack.us/img841/2023/58196854.png" rel="nofollow noreferrer">mysql table http://img841.imageshack.us/img841/2023/58196854.png</a></p>
  
  <p>The piece of (junk) code that I am using to do this is as following:</p>
  
  <pre><code>&lt;div class="rowElem"&gt;
  &lt;label for="service_name"&gt;&lt;b&gt;Particulars&lt;/b&gt;&lt;/label&gt;
  &lt;?php 
              $sql1 = "select * from `service_tbl`";
              $query_result = mysql_query($sql1);
  
          echo "&lt;select id='service_name' name='service_name'&gt;";
          while( $row = mysql_fetch_array( $query_result ) ) {
              echo "&lt;option value='".$row['id_service']."' &gt;".$row['service_name']."&lt;/option&gt;";
              $service_price = $row['service_price'];
          }
          echo "&lt;/select&gt;";
          ?&gt;
  &lt;/div&gt;
  
  &lt;div class="rowElem"&gt;
          &lt;label for='service_price'&gt;&lt;b&gt;Price&lt;/b&gt;&lt;/label&gt;
          &lt;input type='text' id='service_price' name='service_price' value="&lt;?php echo $service_price; ?&gt;" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And the code is doing what it's supposed to do:</p>
  
  <p><a href="http://img94.imageshack.us/img94/6341/67345604.png" rel="nofollow noreferrer">output http://img94.imageshack.us/img94/6341/67345604.png</a></p>
  
  <p>No matter which item I select, in the <code>Price</code> field of the form, I am getting the value <code>800</code> that was fetched at the end of the while loop. Which is the expected behavior according to the code.</p>
  
  <p>But my objective is not being served by this. What I want is, to select an item from drop down menu and show it's corresponding price value in the <code>Price</code> field of the form. How do I do that? <em>I know my MySQL queries are deprecated and I should use <strong>PDO</strong> or <strong>MySQLi</strong> approach.</em> But that's not the main concern for me right now. Any suggestions will be highly appreciated. </p>