如何在php中搜索确切的数字 [英] How to search exact number in php

查看:42
本文介绍了如何在php中搜索确切的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何搜索确切号码

这段代码是这样工作的

如果我搜索24626838(这是完整的否),则什么都没有显示

if i search 24626838(this is complete no) it is showing nothing

在那之后,如果我搜索此否2462683(这不是完整的否)

after that if i search this no 2462683(this is not complete no)

所以它显示这样的结果

像这样

24626838
24626838
24626836
24626832
24626837

我想要这样的结果

如果我搜索此否24626838(这是完整的否)

if i search this no 24626838 (this is complete no)

所以它显示的完全像这样

so it is showing exact like this

24626838
24626838

我该怎么做,请帮助我解决此问题

how can i do this please help me to fix this issue

这是代码

<?php

    //connect to database

     mysql_connect('localhost','root','');
     mysql_select_db('member');

$alphabet = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); 
foreach ($alphabet as $letter) { 
echo "<a href=\"viewuser.php?letter=" . $letter . "\" class=\"style2\">" . $letter . "</a>&nbsp;|&nbsp;"; 

} 


echo "<br>";
echo "<a href=\"index.php?\" class=\"style2\">Show All</a></p><br /> <form method=\"post\" action=\"?\">

        <input type=\"hidden\" name=\"letter\" value=\"{$_GET['letter']}\" />";


$page = (empty($_GET['page'])) ? 1 : $_GET['page'];
$letter = (empty($_GET['letter'])) ? "%" : $_GET['letter'];
$name = (empty($_GET['name'])) ? "%male" : $_GET['name'];
?></td>
            </tr>

            <p> 
              <?php

//get date
$button = $_GET['submit'];
$search = $_GET['search'];

$s = $_GET['s'];
if (!$s)

$s = 0;
$e = 12;

$next = $s + $e; $prev = $s - $e;
    if (strlen($search)<=1)
   echo "";

    else
   {
     echo "<class=\"style2\"> You searched for <b>$search</b>";

     //connect to database

     mysql_connect('localhost','root','');
     mysql_select_db('member');



 //explode search term
           $search_exploded = explode(" ",$search);
           foreach($search_exploded as $search_each)
{
    $str = mysql_real_escape_string(substr($search_each, 0, 9));
    //construct query
    $x++;
    if ($x==1) $construct .= "number LIKE '$str%'";

}




        //echo out construct

  $construct = "SELECT * FROM workorder WHERE $construct";

    $run = mysql_query($construct);
     $foundnum = mysql_num_rows($run);
       if ($foundnum==0)
        echo "<class=\"style2\">No user found.";
     else
     {






 ?>






<?php

 echo "<class=\"style2\"><p>$foundnum results found.</p>";

       while ($runrows = mysql_fetch_assoc($run))
              {
echo "<table class='hovertable' border='1' cellpadding='0' cellspacing='0'>";
echo "<tr><th>User name</th><th>Number</th><th>Exchange</th><th>Cabnint</th><th>Service</th><th>Open Date</th><th>Close Date</th><th>Remaks</th><th>Status</th><th>Edit</th><th>Detail</th><th>Delete</th></tr>";

if ($runrows > 0) {
        while($runrows = mysql_fetch_array($run)) {
                echo "<tr><td>";
             echo $runrows['username'];
            echo "</td><td>";
                echo $runrows['number'];
                echo "</td><td>";
            echo $runrows['exchange'];
        echo "</td><td>";
        echo $runrows['cabnint'];
                echo "</td><td>";
        echo $runrows['service'];
                echo "</td><td>";
        echo $runrows['opendate'];
                echo "</td><td>";
        echo $runrows['closedate'];
                echo "</td><td>";
        echo $runrows['remaks'];
                echo "</td><td>";
        echo $runrows['status'];
                echo "</td><td>";
            echo '<a href="edit.php?id=' . $runrows['id'] . '" class="style2">Edit</a>';
        echo "</td><td>";
            echo '<a href="detail.php?id=' . $runrows['id'] . '" class="style2">Detail</a>';
        echo "</td><td>";
            echo '<a href="delete.php?id=' . $runrows['id'] . '" class="style2">Delete</a>';
                echo "</td></tr>";

        }
} else {
        echo "<tr><td colspan=\"5\">No results found!</td></tr>";
}

echo "</table>";
       }

     }



    }
?>

推荐答案

尝试此方法应该可以

 if ($x==1) $construct .= "number LIKE '".$str."%'";

这篇关于如何在php中搜索确切的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆