Ui Autocomplete在线返回所有值,但在localhost中工作

时间:2015-09-02 07:28:01

标签: javascript php jquery

我正在尝试2天来解决这个问题我会打击我的心情我不能再..当我在localhost中运行它时它工作正常但是当我在线尝试它时它只返回相同的值.. 。并且所有值都不会返回我无法理解的搜索词。

Jquery的

$(document).ready(function($){
$('#quick-search-input2').autocomplete({
    source:'All/home/directsearch.php',
    minLength:2,
    autoFocus: true,
    select: function(event,ui){
        var code = ui.item.id;
        if(code != '') {
            location.href = 'Movies/' + code;
        }
    },
    html: true,
    open: function(event, ui) {
        $('ul.ui-autocomplete').slideDown(500)('complete');
        $(".ui-autocomplete").css("z-index", 1000);
    },
}).data("ui-autocomplete")._renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("" + item.label + "")
.appendTo(ul);
};
});

PHP

$server = 'localhost';
$user = 'root';
$password = '';
$database = 'search';

$mysqli = new MySQLi($server,$user,$password,$database);

/* Connect to database and set charset to UTF-8 */
if($mysqli->connect_error) {
  echo 'Database connection failed...' . 'Error: ' . $mysqli->connect_errno . ' ' . $mysqli->connect_error;
  exit;
} else {
  $mysqli->set_charset('utf8');
}

$term = stripslashes($_GET ['term']);
$term = mysql_real_escape_string($_GET ['term']);
$a_json = array();
$a_json_row = array();
include '../../connect.php';
/* ***************************************************************************** */
if ($data = $mysqli->query("SELECT * FROM search WHERE (title LIKE '%$term%' or keywords LIKE '%$term%') and serie = '' and visible = '' and complete = '' group by title, year order by clicks desc LIMIT 5")) {
    while($row = mysqli_fetch_array($data)) {
        $title = $row['title'];
        $year = htmlentities(stripslashes($row['year']));
        $type = $row['type'];
        $customercode= htmlentities(stripslashes($row['link']));
        $category= htmlentities(stripslashes($row['category']));
        $synopsis= htmlentities(stripslashes($row['synopsis']));
        $img= htmlentities(stripslashes($row['img']));
        $id= htmlentities(stripslashes($row['id']));
        $category = str_replace(" | ",", ", $category);
        $shit = "'";
        $ltitle = strtolower($title);
        if ($type == "DL-HD")
        {
            $qualityresponse = '<img class="quality-banner img-responsive" src="Design/types/HD.png">';
        }
        else if ($type == "Non-HD")
        {
            $qualityresponse = '<img class="quality-banner img-responsive" src="Design/types/NonHD.png">';
        }
        else if ($type == "CAM")
        {
            $qualityresponse = '<img class="quality-banner img-responsive" src="Design/types/CAM.png">';
        }
        else
        {
            $qualityresponse = "";
        }
        $stitle = preg_replace("/[^A-Za-z0-9]/", "", $ltitle);
        $a_json_row["id"] = $customercode;
        $a_json_row["value"] = ''.$term.'';
            $a_json_row["label"] = '
            <a href = Movies/'.$customercode.'><img src="images'.$img.'/'.$stitle.'.jpg">'.$qualityresponse.'<span class="titles">'.$title.'</span><p>'.$year.'</p></center></a>
            ';
        array_push($a_json, $a_json_row);
    }
}
$foundnum = mysql_num_rows(mysql_query("SELECT * FROM search WHERE (title LIKE '%$term%' or keywords LIKE '%$term%') and serie = '' and visible = '' and complete = '' group by title, year order by clicks desc LIMIT 5"));
        if ($foundnum == 0)
        {
            $a_json_row["label"] = '
            <li class="ac-no-results ac-item-hover ac-item-selected">No Movies found</li>
            ';
            array_push($a_json, $a_json_row);
        }
echo json_encode($a_json);
flush();

$mysqli->close();

1 个答案:

答案 0 :(得分:0)

$ term = mysql_real_escape_string($ _ GET ['term']);

$ term = mysqli-&gt; real_escape_string($ _ GET ['term']);