0

<?php

$input = $_GET['input'];//Note to self $input in the name of the search


    $terms = explode(" ", $input);
    $query = "SELECT * FROM  `#####` WHERE 1 LIMIT 0 , 30";

    foreach ($terms as $each){
        $i++;
        if ($i == 1)
            $query .= "keywords LIKE '%$each%' ";
        else
            $query .= "OR keywords LIKE '%$each%' ";
    }

    // connecting to our mysql database
    mysql_connect("#####", "#####", "#####");
    mysql_select_db("#####");

    $query = mysql_query($query);
    $numrows = mysql_num_rows($query);
    if ($numrows!=0){

        while ($row = mysql_fetch_assoc($query)){
            $id = $row['id'];
            $title = $row['title'];
            $description = $row['description'];
            $keywords = $row['keywords'];
            $url = $row['url'];
            echo "<h2><a href='$url'>$title</a></h2>
            $description<br /><br />";

        }

    }
    else
        echo "Não foram encontrados resultados para \"<b>$input</b>\"";

    // disconnect
    mysql_close();
?>
3
Contributors
2
Replies
17
Views
3 Years
Discussion Span
Last Post by pardeepkk
0

Your keywords like ... should come BEFORE limit 0,30. That's why the query fails.

Edited by pritaeas

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.