Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL returning multiple entries when only one match exists (one display incorrect URL)
    primarykey
    data
    text
    <p>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.</p> <p>The code:</p> <pre><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()); ?&gt; &lt;table id="customers"&gt; &lt;?php while($rows = mysql_fetch_array($sql)): ?&gt; &lt;tr class="alt"&gt; &lt;td&gt;&lt;?php echo $rows[Court]; ?&gt;&amp;nbsp&lt;?php echo $rows[Type]; ?&gt;&lt;br&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $rows[City]; ?&gt;,&amp;nbsp&lt;?php echo $rows[State]; ?&gt;&lt;br&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo "&lt;a href=$rows[URL]&gt;Court Info&lt;/a&gt;"; ?&gt;&lt;br&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endwhile; ?&gt; &lt;/table&gt; </code></pre> <p>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. </p> <p>I have tried grouping, ordering and crying, but nothing works.</p> <p>Edit:</p> <p>Adding paranthesis still produces the same problem...</p> <pre><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") </code></pre> <p>Edit: Table Structure...</p> <pre><code>+--------------+--------------+----------+-----------+---------+-------+-------+---------------+--------------+----------+--------------+ | Type | Court | County | Street | City | State | Zip | Email | Website | Phone | URL | +--------------+--------------+----------+-----------+---------+-------+-------+---------------+--------------+----------+--------------+ | Justice of.. | Precinct 1.. | Anderson | P O Box.. | Elkhart | TX | 75839 | gthomas@co... | http://www.. | 903-76.. | http://www.. | +--------------+--------------+----------+-----------+---------+-------+-------+---------------+--------------+----------+--------------+ </code></pre> <p>And the result when a City name doesn't match its County's name:</p> <pre><code>+-------------------+-------------+------------+ | Boerne Municipal | Boerne, TX | Court Info | &lt;&lt;Court info links to the wrong URL (current page) +-------------------+-------------+------------+ | Boerne Municipal | Boerne, TX | Court Info | &lt;&lt;Court Info links to correct URL +-------------------+-------------+------------+ </code></pre> <p>The above results are for the city of Boerne which has only one municipal court entry in the database.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload