# Searching and querying an entire database

**URL:** <https://forum.kirupa.com/t/searching-and-querying-an-entire-database/297835>\
**Category:** programming\
**Created:** [October 8, 2009, 11:27pm UTC](https://forum.kirupa.com/t/searching-and-querying-an-entire-database/297835 "2009-10-08T23:27:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![skindy](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@skindy](https://forum.kirupa.com/u/skindy)\
**Post date:** [October 8, 2009, 11:27pm UTC](https://forum.kirupa.com/t/searching-and-querying-an-entire-database/297835/1 "2009-10-08T23:27:39Z")

</div>

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

<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

<?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!
