Search the entire database?

Discussion in 'PHP' started by red-x, Nov 19, 2008.

  1. #1
    Hi, is there a way to search the entire database instead of just one table?
    I'm using this code to search things in my database but it only works for one table.

    if ($_GET["action"] == "start") {     
    
    $searchString = addslashes($_POST['search']);
    
    if(!empty($searchString)) {
        $result = mysql_query("SELECT * FROM posts WHERE content LIKE '%$searchString%'");
    
        while($row = mysql_fetch_array($result)) {	
            $memberId = $row['id'];
            $post = $row['content'];
            $postDate = $row['date'];
            print "$memberId posted this \"$post\" on $postDate <br /><br />";
        }
    } else {
      echo 'Sorry nothing was found.';
    }
    
    
    } else {
    echo '
    <form method="post" action="?action=start" />
    <input type="text" name="search" size=40 />
    <input type="Submit" name="Submit" value="Search" />
    </form>';
    }
    PHP:
    Thank you in advance :)
     
    red-x, Nov 19, 2008 IP
  2. Shoro

    Shoro Peon

    Messages:
    143
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SELECT table_name FROM information_schema.tables WHERE table_schema = 'databasename'

    Executing that query will give you a list of tables in the database, which you can then use to query each table.
     
    Shoro, Nov 19, 2008 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    Why would you search the whole database!? you know where to search for certain information?
     
    EricBruggema, Nov 19, 2008 IP
  4. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yea searching the entire database would be rhetorical
     
    atlantaazfinest, Nov 20, 2008 IP
  5. AdultProfiles

    AdultProfiles Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You need to get a list of all tables and then write that code for all tables using a while or for.
     
    AdultProfiles, Nov 20, 2008 IP
  6. eric90

    eric90 Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Why on earth would you do that? It's gonna chew up so much resources on the server. I'd just have the information split up and sorted to smaller tables in the first place.
     
    eric90, Nov 21, 2008 IP
  7. AdultProfiles

    AdultProfiles Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes, why u need that?!
     
    AdultProfiles, Nov 21, 2008 IP