MySQL returning multiple entries when only one match exists (one display
incorrect URL)
I have a fairly simple database with only one table which contains the
contact info for Texas Courts. The search form allows users to select that
type of court and then enter the city or county name (seperate fields)
they wish to search for.
The code:
$sql = mysql_query ("SELECT * FROM COURTS
WHERE Type = '$_POST[Type]' AND City LIKE
'$_POST[City]'
OR Type = '$_POST[Type]' AND County LIKE
'$_POST[County]'
ORDER BY County, City")
or die(mysql_error()); ?>
<table id="customers">
<?php while($rows = mysql_fetch_array($sql)): ?>
<tr class="alt">
<td><?php echo $rows[Court]; ?> <?php echo $rows[Type]; ?><br></td>
<td><?php echo $rows[City]; ?>, <?php echo $rows[State]; ?><br></td>
<td><?php echo "<a href=$rows[URL]>Court Info</a>"; ?><br></td>
</tr>
<?php endwhile; ?>
</table>
When searching for a city whose name is different from the county name
(eg. Boerne, Kendall County), MySQL returns two results for the city when
only one exists in the table. The first return has a hyperlink to the
current search result page and the second links to the proper information
page. If a city shares its name with the county (eg. Bandera, Bandera
County) the return is correct - one listing with the proper URL.
I have tried grouping, ordering and crying, but nothing works.
No comments:
Post a Comment