gpt4 book ai didi

php - 包含@的请求不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 10:58:21 25 4
gpt4 key购买 nike

<分区>

我已经为我们工作的数据库设置了快速搜索功能。基本上你搜索一个电子邮件地址,你会根据电子邮件获得匹配。

目前它运行良好,例如我可以编写 anna,并获得像 anna@thedomain.com 这样的点击率。如果我搜索 thedomain.com,它也会起作用。

但是当我写“anna@”时,我得到了“no hits”。因此,当我在搜索字段中包含 @ 时,我只是没有得到任何匹配项。

该脚本基于 index.html,其中附加了一些 jssearch.php 脚本。

下面是index.html的代码:


<!DOCTYPE HTML>
<html>
<head>
<!-- Meta -->
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Live search</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- Load CSS -->
<link href="style/style.css" rel="stylesheet" type="text/css" />

<!-- Load Fonts -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:regular,bold" type="text/css" />
<!-- Load jQuery library -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- Load custom js -->
<script type="text/javascript" src="scripts/custom.js"></script>
</head>
<body>
<div id="main">
<!-- Title -->
<div class="icon"></div>
<h1 class="title">Search</h1>
<h5 class="title">Find relevant data</h5>

<!-- Input -->
<input type="text" id="search" value="E-Mailaddress" onfocus="this.value = ''; return true" onblur="this.value = 'E-Mailaddress'; return true" autocomplete="off">

<!-- Shows The result -->
<h4 id="results-text">Showing results for: <b id="search-string">Array</b> </h4>
<ul id="results"></ul>


</div>

</body>
</html>

search.php 脚本:


<?php
/************************************************
The Search PHP File
************************************************/


/************************************************
MySQL Connect
************************************************/
// Credentials
$dbhost = "localhost";
$dbname = "dbname";
$dbuser = "dbuser";
$dbpass = "dbpassword";

// Connection
global $tutorial_db;

$tutorial_db = new mysqli();
$tutorial_db->connect($dbhost, $dbuser, $dbpass, $dbname);


// Check Connection
if ($tutorial_db->connect_errno) {
printf("Connect failed: %s\n", $tutorial_db->connect_error);
exit();
}

/************************************************
Search Functionality
************************************************/

// Define Output HTML Formating
$html = '';
$html .= '<li class="result">';
$html .= '<a target="_blank" href="urlString">';
$html .= '<h3>nameString</h3>';
$html .= '<h4>functionString</h4>';
$html .= '</a>';
$html .= '</li>';

// Get Search
$search_string = preg_replace("/[^A-Za-z0-9]/", " ", $_POST['query']);
$search_string = $tutorial_db->real_escape_string($search_string);

// Check Length More Than One Character
if (strlen($search_string) >= 1 && $search_string !== ' ') {
// Build Query
$query = "SELECT * FROM table_name WHERE Emailaddress LIKE '%".$search_string."%'";

// Do Search
$result = $tutorial_db->query($query);
while($results = $result->fetch_array()) {
$result_array[] = $results;
}

// Check If We Have Results
if (isset($result_array)) {
foreach ($result_array as $result) {

// Just a normal output
$output = "<li>$result[Dataentry] / <a href='showmore.php?ticketid=$result[ticketref]'>Go to ticket</a> / <strong>$result[Emailaddress]</strong></li>";

// Output
echo $output;
}
}
else{

// Format No Results Output
$output = str_replace('urlString', 'javascript:void(0);', $html);
$output = str_replace('nameString', '<b>Ingen resultater...</b>', $output);
$output = str_replace('functionString', 'Sorry :(', $output);

// Output
echo($output);
}
}


/*
// Build Function List (Insert All Functions Into DB - From PHP)

// Compile Functions Array
$functions = get_defined_functions();
$functions = $functions['internal'];

// Loop, Format and Insert
foreach ($functions as $function) {
$function_name = str_replace("_", " ", $function);
$function_name = ucwords($function_name);

$query = '';
$query = 'INSERT INTO search SET id = "", function = "'.$function.'", name = "'.$function_name.'"';

$tutorial_db->query($query);
}
*/
?>

包含的 custom.js 文件:

/* JS File */

// Start Ready
$(document).ready(function() {

// Icon Click Focus
$('div.icon').click(function(){
$('input#search').focus();
});

// Live Search
// On Search Submit and Get Results
function search() {
var query_value = $('input#search').val();
$('b#search-string').html(query_value);
if(query_value !== ''){
$.ajax({
type: "POST",
url: "search.php",
data: { query: query_value },
cache: false,
success: function(html){
$("ul#results").html(html);
}
});
}return false;
}

$("input#search").live("keyup", function(e) {
// Set Timeout
clearTimeout($.data(this, 'timer'));

// Set Search String
var search_string = $(this).val();

// Do Search
if (search_string == '') {
$("ul#results").fadeOut();
$('h4#results-text').fadeOut();
}else{
$("ul#results").fadeIn();
$('h4#results-text').fadeIn();
$(this).data('timer', setTimeout(search, 100));
};
});

});

index.html, search.php & custom.js 都是用utf-8编码的,我的数据库是 utf8_general_ci

谁能看出为什么这行不通?我是 JavaScript 新手,感觉 JS 有问题。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com