How do I get the search results from my query into a table and then select a entry to update details in my form?
so I have my form: name, address, tel, postcode, email etc.
I have a search query that search's postcode.
I have a list of results which I then want to select one (select button or something similar) and fill the rest of the information back into my form.
Form looks like this
<td><form action="searchresults.php" method="post" name="form1" id="form1">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Find a Active Physio</strong></td>
</tr>
<tr>
<td width="100">Physio Reference</td>
<td width="301"><input name="PhysioReference" type="text" id="PhysioReference" /></td>
</tr>
<tr>
<td>Name of Physio</td>
<td><input name="Physio" type="text" id="Physio" /></td>
</tr>
<tr>
<td>Contact Number</td>
<td><input name="Number" type="text" id="Number" /></td>
</tr>
<tr>
<td>Address</td>
<td><input name="PhysiosAddress" type="text" id="PhysiosAddress" /></td>
</tr>
<tr>
<td>Postcode</td>
<td><input name="postcode" value="" type="text" id="postcode" />
<input type="submit" name="submit" value="Search" /></td>
</tr>
<tr>
<td>Physios Email</td>
<td><input name="PhysiosEmail" type="text" id="PhysiosEmail" /></td>
</tr>
<tr>
<td colspan="3" align="center"> </td>
</tr>
</table>
</form></td>
Search results like this (need to get them into a table please)
<?php
require_once('auth.php');
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="Physio"; // Table name
// Connect to server and select database.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
if(!isset($_POST['postcode'])) {
header ("location:index.php");
}
echo "<p> Results </p>" ;
$search_sql = "SELECT * FROM `Physio` WHERE Postcode like '%" . $_POST['postcode'] . "%'";
$search_query = mysql_query($search_sql);
while ($search_rs = mysql_fetch_array($search_query))
{
echo $search_rs['Reference'] . '<br>';
echo $search_rs['Physio'] . '<br>';
echo $search_rs['Postcode'] . '<br>';
echo $search_rs['Line1'] . '<br>';
echo $search_rs['Tel'] . '<br>';
}
if (!empty($search_rs))
{
echo "<p> Results Found </p>" ;
}
else
{
echo "<p> No Results Found </p>" ;
}
?>
try this
echo"<table><tr>" ;
echo '<th>Reference</th><th>Physio</th><th>Postcode</th><th>Line1</th><th>Tel</th></tr>';
while ($search_rs = mysql_fetch_array($search_query))
{
echo '<tr>';
echo "<td>".$search_rs['Reference'] . "</td>";
echo "<td>".$search_rs['Physio'] . "</td>";
echo "<td>".$search_rs['Postcode'] . "</td>";
echo "<td>".$search_rs['Line1'] . "</td>";
echo "<td>".$search_rs['Tel'] . "</td>";
echo '</tr>';
}
echo '</table>';
For learning purpose of building html tables in php
echo "<td><a href="url">".$search_rs['Reference'] . "</a></td>";