使用 PHP、MYSQL、GROUP_CONCAT 和 JOIN 在空间上搜索 运行

Search running spatially with PHP, MYSQL, GROUP_CONCAT and JOIN

我对代码进行了一些更改,现在可以正常使用了。但是有一个新的问题。 在数据库中,我注册了3个公司代码:G-1001、G-1002和G-1004。

如果我键入 "g"、"g-",或者例如 "g-100" 并单击搜索,它 returns 会正确显示所有结果。但是,如果我只键入 "g-1001" 甚至“01”、“001”,它 returns 没有结果。

为什么我搜索注册码的最后一个字符时不起作用?

<?php  
if(isset($_POST['action']) && $_POST['action'] == 'send'){
    $codsearch = preg_replace('#[^a-z 0-9?()!-]#i', '', $_POST['searchcompanycod']);

    $getresultsquery = mysql_query('SELECT p.*, a.idProduct, a.idVehic, a.year, v.nameVehic, GROUP_CONCAT(a.year SEPARATOR "<br>"), GROUP_CONCAT(a.idVehic SEPARATOR "<br>"), GROUP_CONCAT(v.nameVehic SEPARATOR "<br>")
    FROM products p
    INNER JOIN application a ON p.idProduct = a.idProduct
    INNER JOIN vehic v ON a.idVehic = v.idVehic
    WHERE codCompany LIKE "%'.$codsearch.'%"
    GROUP BY p.codCompany') or die(mysql_error());

    $resultsrow = mysql_num_rows($getresultsquery);
    if($resultsrow > 1){
        echo "$codsearch";
        echo "<table class='table table-bordered' border=1>";
        echo "<tr>";
        echo "<th>Company Code</th><th>Original Code</th><th>Descr.</th><th>idProduct</th><th>idVehic</th><th>Vehic Name</th><th>Year</th>";
        echo "</tr>";

        while($getresultsline = mysql_fetch_array($getresultsquery)) {
            echo "<tr>";  
            echo "<td>" . $getresultsline['codCompany'] . "</td>";
            echo "<td>" . $getresultsline['codOriginal'] . "</td>";
            echo "<td>" . $getresultsline['typeDesc'] . "</td>";
            echo "<td>" . $getresultsline['idProduct'] . "</td>";
            echo "<td>" . $getresultsline['GROUP_CONCAT(a.idVehic SEPARATOR "<br>")'] . "</td>";
            echo "<td>" . $getresultsline['GROUP_CONCAT(v.nameVehic SEPARATOR "<br>")'] . "</td>";
            echo "<td>" . $getresultsline['GROUP_CONCAT(a.year SEPARATOR "<br>")'] . "</td>";  
            echo "</tr>";
        }
    }   else{
            echo "No results";}
}
?>  
</tbody>
</table>

有什么想法吗? 我的测试页面是:http://flyingmail.com.br/test/produtos.php(仅公司代码过滤器有效)

您 SQL 上的突出显示应该会告诉您主要问题。

改变

'SELECT table1.*, table2.productID, table2.veicleID, table2.date, table3.veicleNAME, GROUP_CONCAT(table2.date SEPARATOR "<br>"), GROUP_CONCAT(table3.veicleNAME SEPARATOR "<br>")
    FROM table1
    INNER JOIN table2 ON table1.productID = table2.productID
    INNER JOIN table3 ON table2.veicleID = table3.veicleID
    GROUP BY productID
    HAVING productID LIKE '%".$codsearch."%''

"SELECT table1.*, table2.productID, table2.veicleID, table2.date, table3.veicleNAME, GROUP_CONCAT(table2.date SEPARATOR "<br>"), GROUP_CONCAT(table3.veicleNAME SEPARATOR "<br>")
    FROM table1
    INNER JOIN table2 ON table1.productID = table2.productID
    INNER JOIN table3 ON table2.veicleID = table3.veicleID
    GROUP BY productID
    HAVING productID LIKE '%".$codsearch."%'"

(注意我把第一个和最后一个单引号改成了双引号)

找到了。哈哈哈太糟糕了...它永远不会是 if($resultsrow > 1){ 因为如果我搜索特定的东西,它将 return 只有 1 行。所以,它必须是 if($resultsrow >= 1){

哈哈