我对代码进行了一些更改,现在可以正常工作了。但是有一个新问题。在数据库中,我已经注册了3个公司代码:G-1001,G-1002和G-1004。
如果输入“ g”,“ g-”或“ g-100”,然后单击“搜索”,它将正确返回所有结果。但是,如果我只键入“ g-1001”或什至是“ 01”,“ 001”,则不会返回任何结果。
为什么搜索注册码的最后一个字符时它不起作用?
<?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(仅公司代码过滤器有效)
找到了。哈哈哈糟糕透顶……永远不可能,if($resultsrow > 1){
因为如果我搜索特定内容,它只会返回1行。所以一定是if($resultsrow >= 1){
哈哈
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句