Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 2 of 2

Thread: Searching and querying an entire database

  1. #1

    Searching and querying an entire database

    Hi everyone! I tried a search on this topic in the forums to prevent double-posting but I couldn't find a post nor a solution.

    What I do know
    I'm fairly familiar with MySQL databases in that I know how to use phpMyAdmin. I know how to pull data from a database and display.

    What I don't know
    I don't know how to create a working search function that does the following:
    - Search all the columns within the tables within the database and displays the results

    For example, I have a database called "french_destination" with about 8 tables, those tables are:

    - accommodations
    - sports
    - towns
    - restaurants
    - beaches
    - parks
    - villas
    - agencies

    If a user searched for "colonial" it should search all the columns within those 8 tables and then display all the matching results.

    I'd like to know if this was possible?


    My search form:

    PHP Code:
    <form method="post" action="search.php">
    <
    input type="text" name="search" size=25 maxlength=25>
    <
    input type="Submit" name="Submit" value="Submit">
    </
    form
    This is what I had that only searched a certain table and a certain column: The problem though was that it only searched a certain table and certain column. I need it to search ALL columns within ALL tables and display ALL matching results.

    PHP Code:
    <?php
    $db 
    mysql_connect ("localhost""french_user","french123")  or die (mysql_error());
    mysql_select_db ("french_destination");

    $search $_POST['search'];

    $result mysql_query("SELECT * FROM accommodations WHERE caption LIKE '%$search%'");

    while (
    $row mysql_fetch_array($result)){
        echo 
    'ID: '.$row['accommodations_name'];
        echo 
    '<br/><br/>';
        }
        
        

    ?>
    I researched online and the only things that were semi-useful (but I couldn't grasp them fully) were:

    Using UNION (I already know OR)
    Using show_tables and then querying results from the show_tables results


    Any help would be greatly appreciated!

  2. #2
    MySQL's "LIKE" is not meant for search engines. There's a technique called Full-Text Search ( http://devzone.zend.com/article/1304 ) that can actually sort your searches by relavence. I don't know what algorithm it uses - probably not as good as Google's - but it's way better than LIKE; there's no doubt about that.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012