biscuitboy
Technical User
Hiya,
Below is a script that searches a mysql database and returns records based on the surname entered into the form. Currently when the records are returned they are displayed above the form. Is there anyway to have the records displayed underneath the form??
best regards
Code:
<?php # Scrtipt 6.6 - surname.php
$page_title = 'surname';
$message = NULL;
if (empty($_GET['surname'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter a surname!</p>';
} else {
$ln = $_GET['surname'];
}
if ($ln) { //if everthings is ok.
require_once ('connect.php'); // Connect to the db.
//Make the Query
$query = "SELECT surname, first_name, flat_no, building_name, tel_no, organisations, Disabilities, Reasons FROM Residents WHERE surname= '$ln'";
$result = mysql_query ($query) or die (mysql_error()); // run the query
$num = mysql_num_rows ($result); // how many users are there
if ($num > 0) { // if it ran ok display the records
echo "<p><big><b> There are currently $num residents registered.</b></big></p>";
echo '<table align="centre"
cellspacing="2" cellpadding="4">
<tr><b><td align="left"><b>Surname</b>
</td><td align="left"><b>First Name</b>
</td><td align="left"><b>Flat No</b>
</td><td align="left"><b>Building Name</b>
</td><td align="left"><b>Tel No</b>
</td><td align="left"><b>Organisations</b>
</td><td align="left"><b>Disabilities</b>
</td><td align="left"><b>Reasons</b>
</td></tr>
';
//fetch and print all the records.
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
echo "<tr><td align=\"left\">" .
stripslashes($row[0]) . "</td>
<td align=\"left\">$row[1]</td>
<td align=\"left\">$row[2]</td>
<td align=\"left\">$row[3]</td>
<td align=\"left\">$row[4]</td>
<td align=\"left\">$row[5]</td>
<td align=\"left\">$row[6]</td>
<td align=\"left\">$row[7]</td>
</tr>\n";
}
echo '</table>';
mysql_free_result ($result); //Free up the resources.
} else {
$message .= '<p>Please try again.</p>';
}
} else {
$message .= '<p>Please try again.</p>';
}
mysql_close(); // close the database connection
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<fieldset><legend>Enter a Surname below:</legend>
<p><b>Last Name:</b> <input type="text" name="surname" size="30" maxlength="30" value="<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>" /></p>
<div align="centre"><input type="submit" name"submit" value="Search" /></div>
</form><!-- end of form -->
Below is a script that searches a mysql database and returns records based on the surname entered into the form. Currently when the records are returned they are displayed above the form. Is there anyway to have the records displayed underneath the form??
best regards
Code:
<?php # Scrtipt 6.6 - surname.php
$page_title = 'surname';
$message = NULL;
if (empty($_GET['surname'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter a surname!</p>';
} else {
$ln = $_GET['surname'];
}
if ($ln) { //if everthings is ok.
require_once ('connect.php'); // Connect to the db.
//Make the Query
$query = "SELECT surname, first_name, flat_no, building_name, tel_no, organisations, Disabilities, Reasons FROM Residents WHERE surname= '$ln'";
$result = mysql_query ($query) or die (mysql_error()); // run the query
$num = mysql_num_rows ($result); // how many users are there
if ($num > 0) { // if it ran ok display the records
echo "<p><big><b> There are currently $num residents registered.</b></big></p>";
echo '<table align="centre"
cellspacing="2" cellpadding="4">
<tr><b><td align="left"><b>Surname</b>
</td><td align="left"><b>First Name</b>
</td><td align="left"><b>Flat No</b>
</td><td align="left"><b>Building Name</b>
</td><td align="left"><b>Tel No</b>
</td><td align="left"><b>Organisations</b>
</td><td align="left"><b>Disabilities</b>
</td><td align="left"><b>Reasons</b>
</td></tr>
';
//fetch and print all the records.
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
echo "<tr><td align=\"left\">" .
stripslashes($row[0]) . "</td>
<td align=\"left\">$row[1]</td>
<td align=\"left\">$row[2]</td>
<td align=\"left\">$row[3]</td>
<td align=\"left\">$row[4]</td>
<td align=\"left\">$row[5]</td>
<td align=\"left\">$row[6]</td>
<td align=\"left\">$row[7]</td>
</tr>\n";
}
echo '</table>';
mysql_free_result ($result); //Free up the resources.
} else {
$message .= '<p>Please try again.</p>';
}
} else {
$message .= '<p>Please try again.</p>';
}
mysql_close(); // close the database connection
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<fieldset><legend>Enter a Surname below:</legend>
<p><b>Last Name:</b> <input type="text" name="surname" size="30" maxlength="30" value="<?php if (isset($_POST['surname'])) echo $_POST['surname']; ?>" /></p>
<div align="centre"><input type="submit" name"submit" value="Search" /></div>
</form><!-- end of form -->