Hi Folks,
I'm a relative newcommer to PHP. I've been using it for a little while (along with CSS) for webpage layouts, but now I'm trying to create a database for work that I can search.
That's easy I hear you say, just trawl Google for a script, botch it to fit your needs and Bob's your Mothers Brother. Well I've done that and it worked just fine, but I can only find a script that will search one field, I'd like one that searches on multiple fields (I know, some people want the moon on a stick.)
So I had a go at altering the script I found, all to no avail, I've been reading manuals all Christmas, and I'm still stuck. can anyone help me? Here are the scripts/pages so far...
Search Page
<form action="results.php" method="post">
<table width="50%" border="0">
<tr>
<td> Choose Search Type:</td>
<td><select name="search_type_1">
<option value="Tenant_Surname">Tenant Surname</option>
<option value="Road">Road</option>
<option value="Area">Area</option>
<option value="Post_Code">Post Code</option>
<option value="Telephone">Telephone</option>
<option value="Status_ID">Status</option>
</select></td>
</tr>
<tr>
<td>Enter Search Term: </td>
<td><input name="search_term_1" type="text" /></td>
</tr> <tr>
<td> Choose Search Type:</td>
<td><select name="search_type_2">
<option value="Tenant_Surname">Tenant Surname</option>
<option value="Road">Road</option>
<option value="Area">Area</option>
<option value="Post_Code">Post Code</option>
<option value="Telephone">Telephone</option>
<option value="Status_ID">Status</option>
</select></td>
</tr>
<tr>
<td>Enter Search Term: </td>
<td><input name="search_term_2" type="text" /></td>
</tr>
</table>
<input name="submit" type="submit" value="Search" />
</form>
Results Page.
<?
trim($search_term_1);
if (!$search_type_1 || !$search_term_1)
{
echo "<br />You have not specified any search terms.<br /><br />";
}
$search_type_1 = addslashes($search_type_1);
$search_term_1 = addslashes($search_term_1);
@ $db = mysql_pconnect("localhost", "******", "******");
if (!$db)
{
echo "Error : could not connect to database.";
}
mysql_select_db("test");
$query = "select * from Property where ".$search_type_1." LIKE '%".$search_term_1." AND ".$search_type_2." LIKE '%".$search_term_2."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of records found: ".$num_results."</p>";?>
<table border="0" cellspacing="2" cellpadding="2" width="100%">
<tr>
<td width="24%">Address</td>
<td width="6%">Post Code</td>
<td width="10%">Tenant Name</td>
<td width="3%">IE</td>
<td width="13%">Inspection Date</td>
<td width="3%">WE</td>
<td width="13%">Works Date</td>
<td width="4%">Status</td>
<td width="24%"></td>
</tr>
<?
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);?>
<tr>
<td><? echo $row["House_No"]; ?> <? echo $row["Road"]; ?> <? echo $row["Address_Line_2"]; ?> <? echo $row["Address_Line_3"]; ?></td>
<td><? echo $row["Post_Code"]; ?></td>
<td><? echo $row["Tenant_Title"]; ?> <? echo $row["Tenant_Initials"]; ?> <? echo $row["Tenant_Surname"]; ?></td>
<td><? echo $row["Inspecting_Engineer"]; ?></td>
<td><? echo $row["Inspection_Date"]; ?></td>
<td><? echo $row["Works_Engineer"]; ?></td>
<td><? echo $row["Works_Date"]; ?></td>
<td><? echo $row["Status_ID"]; ?></td>
<td><a href="/***/admin/update.php?Property_ID=<? echo $row["Property_ID"]; ?>" title="View Property" class="links">View Property</a></td>
<?
}
?>
Hope someone can help, It would make my New Year.
Rory