Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Thanked 0 Times in 0 Posts

    mysql/php search page how to [ was mysql help ]

    OK. SO this will a my very first project. It's very simple but since I do not know any mysql stuff.

    I need to make a database with following three items.

    1) City Name
    2) Country in which city is located in.
    3) City's Zip Code

    That will be the MySQL part.

    On the php section. I want to make a search.php page in which you can type any of the above and it will return a small table with all of the values.

    For example.
    If in my database. there were:
    San Fransisco, California, 95001
    San Jose, California, 95111
    new york city, new york, 10111

    and in the search.php's search box if I was to type 10111. The results will return me New York City, New Youk, 10111.

    Contact me for more info. Thanks and have a peaceful day.
    Last edited by guelphdad; 08-01-2006 at 02:20 PM. Reason: insufficient info in thread title

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Thanked 1 Time in 1 Post
    do you know how to use phpMyAdmin? if so, use that to create your mysql table.

    as far as the php search page, you need a search form and probably would be a good idea to have a more limiting search form that has a "search by" feature... otherwise in the case of New York, New York, a query like you suggested would bring up all cities in the state New York as well as the city New York, New York.... so have a dropdown that options for Search By:
    <select name='searchby'>
    <option value='city'>City</option>
    <option value='state'>State</option>
    <option value='zipcode'>Zipcode</option>

    and then have your text field
    <input type="text" name="keyword">

    then on the page your submit the form to, just run the following
    PHP Code:
    $_POST['searchby'] == "city"){
    $sql myql_query("SELECT * FROM `table_name` WHERE `city` LIKE '%{$_POST['keyword']}%'") or die(mysql_error());
    $_POST['searchby'] == "state"){
    $sql mysql_query("SELECT * FROM `table_name` WHERE `state` LIKE '{$_POST['keyword']}'") or die(mysql_error());
    $_POST['searchby'] == "zipcode"){
    $sql mysql_query("SELECT * FROM `table_name` WHERE `zipcode` LIKE '{$_POST['keyword']}%'") or die(mysql_error());
    $row mysql_fetch_array($sql)){
    "$row[city], $row[state] $row[zipcode]<br />";

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    St. Catharines, Ontario Canada
    Thanked 148 Times in 139 Posts
    Quote Originally Posted by desiguru
    Contact me for more info. Thanks and have a peaceful day.
    Please do not post a request for personal help to a problem you have posted to this forum. It is not acceptable practice. You have posted in a forum so you should expect to receive help in the forum. You can also post back any solution so that folks who follow into this thread with a similar concern can see how to approach the problem.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts