php - 无法创建根据相关关键字搜索 1+ 个数据库的函数

标签 php mysql keyword

<分区>

好的,所以我已经编写了这个脚本,它允许我找到但是它不能正常工作。我遇到编程问题 - 编程使其正常工作。它似乎无法正常工作。

此函数在显示在充满银行对帐单付款的数据库中的每一行上声明。 $a, $b, $c, $d 只是类型(BAC、TRS 等)、描述(35 QUEENS ROAD RENT)和金额(£500.00)。

我正在尝试创建一个函数来核对支付给特定用户的款项,具体取决于与他们相关的地址/特性、他们的姓名以及他们的租金。

这是我目前所拥有的:

   function reconcile($a,$b,$c,$d) {

    //when the user clicks on the text fild, jquery loads the various names needed from the database
    //when the user clicks on the selected field, the value is saved via ajax and saved on the server the reconciled field

    //break down the inputs into an array
    //create SQL query that matches all of these key words

    //create keywords database
    $keywords = $a . " " . $b . " " . $c . " " . $d;

    //remove commas, dashes and other keywords from database that might be a nuisance
    //change names like ave to avenue
    $keywords = str_replace("'", "", $keywords);
    $keywords = str_replace("-", "", $keywords);
    $keywords = str_replace(",", "", $keywords);
    $keywords = str_replace("A/C", "", $keywords);
    $keywords = str_replace("TO", "", $keywords);
    $keywords = str_replace("CALL", "", $keywords);
    $keywords = str_replace("REF.NO.", "", $keywords);
    $keywords = str_replace("TO", "", $keywords);
    $keywords = preg_replace("/\s+/", " ", $keywords);
    $keywords = str_replace("  ", "", $keywords);
    $keywords = addslashes($keywords);
    $keywords = mysql_real_escape_string($keywords);

    $keywords = explode(" ", $keywords);
    //$keywords = remove_from_array($keywords, 2);




    //match keywords to keywords database

    $matches = array();

    //search 5 databases...

    $i=0;

    foreach($keywords as $keyword) {

        //add more fields
        //check distinct

        //do not allow any keywords that are smaller than 3
        if(strlen($keyword) < 3) {
            continue;
        }

        $get = mysql_query("SELECT DISTINCT `users`.`id` FROM `users` LEFT JOIN `addresses` ON `users`.`id` = `addresses`.`user` WHERE (`users`.`fname` LIKE '%$keyword%' OR `users`.`lname` LIKE '%$keyword%') OR (((`addresses`.`flat` LIKE '%$keyword%' OR `addresses`.`address` LIKE '%$keyword%') OR (`addresses`.`district` LIKE '%$keyword%' OR `addresses`.`town` LIKE '%$keyword%')) OR (`addresses`.`county` LIKE '%$keyword%' OR `addresses`.`postcode` LIKE '%$keyword%'));") or die("Error: " . mysql_error());
        if(mysql_num_rows($get) > 0) {
            while($fetch = mysql_fetch_array($get)) {
                list($uid) = $fetch; //$uid = user id
                //insert $uid into array
                //1 => 3 times
                //find number if exists and then add to that number

                //search array and echo attempts (if any)

                if(in_array($uid, $matches)) {
                    //add one to the key
                    $matches[$uid]++;
                } else {
                    array_push($matches, $uid);
                }

                $i++;

                //save search to database

            }

            //create array for user
            //add up relevance for that user

        }

    }

    $relevance = 0;

    if($i > $relevance) {
        //change javascript function and link with ajax.php
        echo "<span onClick=\"javascript:void(0)\" style=\"cursor:pointer;\" class=\"label label-success\">Accept</span>\n\r";
        //change to jquery function that allows a drop down of names from the database
        echo "<input type=\"text\" style=\"width:140px\" value=\"" . $matches[0] . "\" />\n\r";
    }

}

我正在考虑添加一个执行此操作的数组:

[0] (user id) => 3(通过银行对帐单的一行找到该用户id的次数)

因此,例如,如果用户 3 在 37 Kings Avenue 拥有特性,并且关键字是“Avenue”,则结果将为 [3] => 1,对于其他用户则依此类推。

“接受”按钮意味着用户将接受系统的协调,文本输入将显示其他相关名称/所有名称和地址的下拉列表。

最佳答案

如果你想从你的数据库/表/ View 中搜索一些数据,你可以使用 SQLyog's Data search特征。它在您的服务器中搜索数据。它像谷歌搜索一样工作! “数据搜索”功能让您无需实际编写任何 SQL 即可查找特定数据。您可以按数据库或表的数据类型/子集过滤数据。

您可以尝试下载 30-day trial并评估这个 MySQL GUI。

enter image description here

关于php - 无法创建根据相关关键字搜索 1+ 个数据库的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11297825/

相关文章:

php - MYSQL 多表选择查询

mysql - PL/SQl - 找出年薪的总增长

python - 普通参数与关键字参数

php - 确定数据库是否已更改的最佳方法?

javascript - 如何使用 FormData API 发出 POST 请求

php - 查询仅返回 1 条记录

php - 使用 PDO 插入多行

python - Python中Pass和None有什么区别

c++ - c++ 类访问关键字 "signals"是什么意思?

php - 如何使用php和mysql返回多维数组中的多级类别