No announcement yet.

PHP/MySQL Help needed please...

  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP/MySQL Help needed please...

    For all the PHP/MySQL gurus around here...

    I'm still relatively new at PHP/MySQL and am having a couple issues with a store locator script, I'm trying to code. The main purpose of it is to have a MySQL database of addresses that can be searched by Country, State, and City, but that also limits the results according to a predefined variable. The main two problems I can't figure out is how to:

    1. Have some error text (ie: There were over xx results to your search, please refine your search criteria.) appear before the results if the LIMIT number is exceeded in the search results.

    2. Secondly, I can't seem to figure out how to allow more than one criteria (ie: country and State instead of only State) to be specified in a search without seperating them into seperate forms. Ideally I'd like to be able to allow a search that could include Country and State from a drop down and City from a text field all at once if a user were to enter all three.

    Any help or a link to where I might find answers would be greatly appreciated. (Thanks in advance)

    Here's the code so far (Only searches by state seem to be working):

    include ("include/");
    include ("include/dbconnect.php");
    	$max = "3";
    if ($searchstring)
    	$sql="SELECT * FROM $table WHERE $searchtype LIKE '%$searchstring%' ORDER BY storename ASC LIMIT $max";
    	$result = mysql_query($sql);
    	$resultsnumber = mysql_numrows($result);
    	echo "<table>";
    	echo "<tr><td>$resultsnumber results found<br><br></td></tr>";
    	$alternate = "2"; 
    		while ($myrow = mysql_fetch_array($result))
    		$storename = $myrow["storename"];
    		$id = $myrow["id"];		
    		if ($alternate == "1") { 
    		$color = "#ffffff"; 
    		$alternate = "2"; 
    		else { 
    		$color = "#efefef"; 
    		$alternate = "1"; 
    			echo "<tr><td>$storename</td>";
    			echo "<td><a href='view.php?id=$id'>see details</a></td></tr>";
    	echo "<tr><td><br><br><a href='$PHP_SELF'>search again</a></td></tr>";
    	echo "</table>";
    	<form method="POST" action="<? $PHP_SELF ?>">
      <table border="0" cellspacing="2" width="380">
    		<td><input type="hidden" name="searchtype" value="country">
    		<select name="searchstring">
    		<option value="" selected>Select</option>
    <option value="USA">USA</option>
    <option value="Canada">Canada</option>
    <option value="Japan">Japan</option>
    <option value="Europe">Europe</option>
    		<td><input type="hidden" name="searchtype" value="state">
    		<select name="searchstring">
    		<option value="" selected>Select</option>
    <option value="AK">ALASKA</option>
    <option value="AL">ALABAMA</option>
    <option value="AR">ARKANSAS</option>
    <option value="AZ">ARIZONA</option>
    <option value="CA">CALIFORNIA</option>
    <option value="CO">COLORADO</option>
    <option value="CT">CONNECTICUT</option>
    <option value="DC">DISTRICT OF COLUMBIA</option>
    <option value="DE">DELAWARE</option>
    <option value="FL">FLORIDA</option>
    <option value="GA">GEORGIA</option>
    <option value="HI">HAWAII</option>
    <option value="IA">IOWA</option>
    <option value="ID">IDAHO</option>
    <option value="IL">ILLINOIS</option>
    <option value="IN">INDIANA</option>
    <option value="KS">KANSAS</option>
    <option value="KY">KENTUCKY</option>
    <option value="LA">LOUISIANA</option>
    <option value="MA">MASSACHUSETTS</option>
    <option value="MD">MARYLAND</option>
    <option value="ME">MAINE</option>
    <option value="MI">MICHIGAN</option>
    <option value="MN">MINNESOTA</option>
    <option value="MO">MISSOURI</option>
    <option value="MS">MISSISSIPPI</option>
    <option value="MT">MONTANA</option>
    <option value="NC">NORTH CAROLINA</option>
    <option value="ND">NORTH DAKOTA</option>
    <option value="NE">NEBRASKA</option>
    <option value="NH">NEW HAMPSHIRE</option>
    <option value="NJ">NEW JERSEY</option>
    <option value="NM">NEW MEXICO</option>
    <option value="NV">NEVADA</option>
    <option value="NY">NEW YORK</option>
    <option value="OH">OHIO</option>
    <option value="OK">OKLAHOMA</option>
    <option value="OR">OREGON</option>
    <option value="PA">PENNSYLVANIA</option>
    <option value="RI">RHODE ISLAND</option>
    <option value="SC">SOUTH CAROLINA</option>
    <option value="SD">SOUTH DAKOTA</option>
    <option value="TN">TENNESSEE</option>
    <option value="TX">TEXAS</option>
    <option value="UT">UTAH</option>
    <option value="VA">VIRGINIA</option>
    <option value="VT">VERMONT</option>
    <option value="WA">WASHINGTON</option>
    <option value="WI">WISCONSIN</option>
    <option value="WV">WEST VIRGINIA</option>
    <option value="WY">WYOMING</option>
    	<tr><td><input type="submit" value="Submit"></td>
    include ("include/");

  • #2
    I see you have the select name the same for country and state. it will only use one, so you have to name one different then add that one to the select query.


    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.