title: Echo Field Value In Text Field
body: <p>I wonder whether someone may be able to help me please.</p>
  
  <p>Through some guidance I received earlier from this site I have been able to put together the script, below that lists date information with an associated radio button allowing each record to be selected.</p>
  
  <pre><code>&lt;?php
  
  mysql_connect("hostname", "username", "password")or
  die(mysql_error());
  mysql_select_db("database");
  ?&gt;
  &lt;html&gt;&lt;head&gt; 
  &lt;title&gt;Location&lt;/title&gt;
  &lt;style type="text/css"&gt;
  &lt;!--
  .style3 {
      font-size: 18px;
      font-family: Calibri;
  }
  --&gt;
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;form name="addimages"&gt;
    &lt;p&gt;
      &lt;label&gt;
      &lt;div align="center" class="style3"&gt; Location Name &lt;br&gt;
        &lt;br&gt;
        &lt;input name="locationname" type="text" value="&lt;?php echo $locationname;?&gt;" id="locationname" size="80"&gt;
      &lt;/div&gt;
      &lt;/label&gt;
    &lt;/p&gt; 
    &lt;p&gt;&amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
      &lt;?php
  
  $result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, finds.userid, finds.locationid, detectinglocations.locationid, detectinglocations.locationname,  finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 ORDER BY dateoftrip DESC");
  if (mysql_num_rows($result) == 0)
  // table is empty
    echo 'There are currently no finds recorded for this location.';
   else
  {
  
    while (list($userid, $dateoftrip, $locationname) =
      mysql_fetch_row($result))
  
    {  
        echo"&lt;table&gt;\n"; 
        echo"&lt;tr&gt;\n"
      .
       "&lt;td&gt;&lt;input type='radio' name='radio' dateoftrip value='{$userid}' /&gt;&lt;/td&gt;\n"
      ."&lt;td&gt;&lt;small&gt;{$dateoftrip}&lt;/small&gt;&lt;td&gt;\n"
      ."&lt;/tr&gt;\n";
    }
    echo"&lt;tr&gt;&lt;td colspan=\"3\"&gt;";
    echo"&lt;br&gt;";
    echo"&lt;/td&gt;&lt;/tr&gt;";
    echo'&lt;/table&gt;';
  }
  ?&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>What I'm now trying to do is add the 'locationname' value to the appropriate text field.</p>
  
  <p>I've added <code>value="&lt;?php echo $locationname;?&gt;"</code> to the textfield but it remains blank. </p>
  
  <p>I think that the problem lies here:</p>
  
  <p><code>while (list($userid, $dateoftrip, $locationname) = mysql_fetch_row($result))</code> which I use to get the information for the list of dates, whilst normally I would use this:<br>
  <code>while ($row = mysql_fetch_array($result))
      {
        $locationname = $row['locationname'];</code> to fetch the value for a text field.</p>
  
  <p>Could someone perhaps tell me please is there a way that I can combine the two statements to bring together the two pieces of information I need i.e. the table containing the list of dates whilst 'echoing' the 'locationname' value into the text field.</p>
  
  <p>Many thanks</p>
  
  <p><strong>UPDATED CODE</strong></p>
  
  <pre><code>&lt;?php
  mysql_connect("hostname", "username", "password")or
  die(mysql_error());
  mysql_select_db("database");
  
  $locationname=''; 
  $result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, finds.userid, finds.locationid, detectinglocations.locationid, detectinglocations.locationname,  finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 ORDER BY dateoftrip DESC");
  if (mysql_num_rows($result) == 0){
  // table is empty
    $return = 'There are currently no finds recorded for this location.'; 
    }else{     
    $return="&lt;table&gt;\n";     
    while (list($userid, $dateoftrip, $locationname) = mysql_fetch_row($result)){ 
  
  $return .="&lt;tr&gt;\n". 
  "&lt;td&gt;&lt;input type='radio' name='radio' dateoftrip value='{$userid}' /&gt;&lt;/td&gt;\n" 
  ."&lt;td&gt;&lt;small&gt;{$dateoftrip}&lt;/small&gt;&lt;td&gt;\n" 
  ."&lt;/tr&gt;\n"; 
  } 
  $return .="&lt;tr&gt;&lt;td colspan=\"3\"&gt;&lt;br&gt;"; 
  } 
  ?&gt;
  &lt;form name="addfinds"&gt;
  
        &lt;input name="locationname" type="text" value="&lt;?php echo $locationname;?&gt;" id="locationname" size="80"&gt;   
    &lt;p&gt;&amp;nbsp;&lt;/p&gt; 
    &lt;p&gt; 
      &lt;?php echo $return;?&gt; 
  &lt;/p&gt; 
  &lt;/form&gt; 
  </code></pre>