1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP Searching Database Using Like

Discussion in 'Web Development' started by gilbertsavier, Aug 4, 2009.

  1. gilbertsavier

    gilbertsavier New Member

    Hi,
    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.

    Thanks & regards
    Lokananth
     
  2. Carmi Stanko

    Carmi Stanko New Member

    Search engine create their database by following links and indexing the content they find. They can not specifically search someone elses database unless there exists a link to the data. So the search engines ability to see the content is based on finding a link to the data. A quick rule of thumb is that when using a web browser, any page you can find by clicking links can be found by a search engine. Any page that can only be found by entering information via a keyboard is unlikely to be indexed.