Hi everyone,
I have two tables, landlords and properties. My properties table has; ID, Address, Postcode, lease and landlordID in it. The problem I face is: If I want to search for all the properties that have Mr.Spina as their landlord I need search the landlords database with the name "spina" to get his ID which is saved in the properties database from which I can extract the properties details.
I thought this would work but it doesn't properly:
> SELECT property.ID, property.address, property.postcode, property.lease, landlords.firstName, landlords.lastName FROM property INNER JOIN landlords ON landlords.firstName LIKE '%spina%' OR landlords.lastName LIKE '%spina%'
I have attached images of the table structures.
Landlords:
only allowed one link
Properties:
http://img5.imageshack.us/img5/7199/propertyn.gif
The result of inserting "spina" into the field should then be: only allowed one link
Here is my extracted code...
> if($field=="landlord"){
>
> $sql="SELECT property.ID, property.address, property.postcode,
> property.lease, landlords.firstName,
> landlords.lastName FROM ".$do." INNER
> JOIN landlords ON landlords.firstName
> LIKE '%".$q."%' OR landlords.lastName
> LIKE '%".$q."%'";
> } else{
> $sql="SELECT * FROM ".$do." WHERE " . $field . " LIKE '%" . $q . "%'";
> } //end special case $result =
> mysql_query($sql);
> echo "$sql";
> echo "<table border='1'>
> <tr>
> <th>ID</th>
> <th>Address</th>
> <th>Post Code</th>
> <th>Lease</th>
> <th>Landlord</th>
> </tr>";
>
> while($row =
> mysql_fetch_array($result))
> {
> echo "<tr>";
> echo "<td>" . $row['ID'] . "</td>";
> echo "<td>" . $row['address'] . "</td>";
> echo "<td>" . $row['postcode'] . "</td>";
> echo "<td>" . $row['lease'] . "</td>";
> echo "<td>" . $row['firstName'] ." ". $row['lastName'] ."</td>";
> echo "</tr>";
> } echo "</table>";
>
> mysql_close();
Many thanks in advance!