Searching Database Using Like
gilbertsavier
Status: Interested
Joined: 28 Jun 2009
Posts: 12
Reply Quote
Hello,
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.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours