dsgwdigu84950 2015-12-08 14:01
浏览 120
已采纳

使用PHP,MYSQL,GROUP_CONCAT和JOIN进行空间搜索

I made some changes in the code and now it's working. But there is a new problem. In the database, I have registered 3 Company Cods: G-1001, G-1002 and G-1004.

If I type "g", "g-", or for instance "g-100" and click search, it returns me all the results correctly. But if I type just "g-1001" or even "01", "001", it returns no results.

Why it's not working when I search the last characters of the registered code?

<?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>

Any ideas? My testing page is: http://flyingmail.com.br/test/produtos.php (only Company Code filter working)

展开全部

  • 写回答

2条回答 默认 最新

  • dongpao5658 2016-01-12 19:30
    关注

    Found it. Hahaha terrible... it could never be if($resultsrow > 1){ because if I search for something specific, it will return only 1 row. So, it must be if($resultsrow >= 1){

    LOL

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 QGC打开没有地图显示,离线地图也不显示,如何解决?
  • ¥20 Android Studio 的 webview 与访问网络存在的限制
  • ¥15 某帖子的数据集不清楚来源,求帮助
  • ¥50 tc358743xbg寄存器配置
  • ¥15 idea构建mod报错无效的源发行版项目链接,如何解决?
  • ¥15 springboot中的路径问题
  • ¥80 App Store Connect 中设置了订阅项目,Xcode 中预览可以正确显示价格,真机测试却无法显示
  • ¥15 MATLAB的PIV算法问题
  • ¥15 RflySim例程学习:matlab编译报错
  • ¥20 谁来给我解答一下疑惑
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部