[英]Search running spatially with PHP, MYSQL, GROUP_CONCAT and 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.
在数据库中,我已经注册了3个公司代码:G-1001,G-1002和G-1004。
If I type "g", "g-", or for instance "g-100" and click search, it returns me all the results correctly. 如果我键入“ g”,“ g-”或“ g-100”,然后单击“搜索”,它将正确返回所有结果。 But if I type just "g-1001" or even "01", "001", it returns no results.
但是,如果我只键入“ g-1001”或什至是“ 01”,“ 001”,则不会返回任何结果。
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)
我的测试页面是: http : //flyingmail.com.br/test/produtos.php (仅公司代码过滤器有效)
The highlighting on your SQL should show you the main issue. SQL上的突出显示应向您显示主要问题。
Change 更改
'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."%''
to 至
"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."%'"
(note that I changed the first and last single quote to a double quote) (请注意,我将第一个和最后一个单引号更改为双引号)
Found it. 找到了。 Hahaha terrible... it could never be
if($resultsrow > 1){
because if I search for something specific, it will return only 1 row. 哈哈哈糟糕透顶...永远不可能
if($resultsrow > 1){
因为如果我搜索特定内容,它只会返回1行。 So, it must be if($resultsrow >= 1){
因此,必须为
if($resultsrow >= 1){
LOL 大声笑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.