# Searching Database Using Like

**URL:** <https://forum.kirupa.com/t/searching-database-using-like/293957>\
**Category:** programming\
**Created:** [August 6, 2009, 9:34am UTC](https://forum.kirupa.com/t/searching-database-using-like/293957 "2009-08-06T09:34:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilbertsavier](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://forum.kirupa.com/u/gilbertsavier)\
**Post date:** [August 6, 2009, 9:34am UTC](https://forum.kirupa.com/t/searching-database-using-like/293957/1 "2009-08-06T09:34:37Z")

</div>

I am trying to query my database for specific words in variables.

I have one database titled pranks with a column called prankentry and tags

Another database holds an ID number and an entrytext column.

I pass the ID number through the URL to /pranks/index.php?id=26. On index.php i am running a query to try and find similar items in the pranksentry row.

Here’s my code:  
$id = $\_GET[‘id’]; //GET ID  
$query = “SELECT entrytext FROM hmr WHERE id=$id”; //GET POST  
$result = mysql\_query($query);

while($row = mysql\_fetch\_array($result))  
{  
$text = $row[‘entrytext’]; //CHANGE VARIABLE

}  
$sql = “SELECT \* FROM pranks WHERE pranksentry LIKE ‘%$text%’ ORDER BY id DESC”; //GET PRANKS SIMILAR to TEXT  
$result5 = mysql\_query($sql);

```
while($row = mysql_fetch_array($result5))

```

{  
$prank = $row[‘prankentry’];  
echo $prank; //OUTPUT Prank  
}  
It’s very strange. By setting $text = ‘test’ and putting a prank into my that table with the text, ‘testing to do this testing to do that’. The code above displays that line.  
However, if i set $text = “he talks too much, and never shuts up.” and have a prank in my database with the text, ‘shuts’, it does not show the results i would like.
