查找用户的搜索栏

Search Bar To Find Users

打开新主题,因为取得了进展,现在需要更多帮助。

我创建了find.php:

         <h5>Search: </h5>
        <form action="search.php" method='get'>
            <input type='text' name='fullname' size='25' /> 
            <input type='submit' value='Search' /> 
    </form>

还有另一页search.php

         <h5>Search: </h5>
        <form action="search.php" method='get'>
            <input type='text' name='fullname' value='<?php echo $_GET['fullname']; ?>' size='25' /> 
            <input type='submit' value='Search' /> 
    </form>
   <?php
   $fullname = $_GET['fullname'];
   $terms = explode(" ", $fullname);

   $query = "SELECT * FROM users WHERE ";

   foreach($terms as $each){
        $i++;

        if($i == 1)
            $query .= "fullname LIKE '%$each%'";
        else
            $query .= "OR fullname LIKE '%$each%'";

   }  

    $query = mysql_query($query);
    $numrows = mysql_num_rows($query);

        if($numrows > 0){

            while($row = mysql_fetch_assoc($query)){
                $id = $row['id'];
                $fullname = $row['id'];
                $profile_picture = $row['profile_picture'];

                echo "<img src='www.secrethashtags.com/uploads/profile_picture/$profile_picture' height='50' width='50'> <br><a href='www.secrethashtags.com/profile.php?id=$id'>Aviv Day </a></br>";
            }

        } else
            echo "No #Results.";


   ?>

现在,我正在我的网站上尝试它,但它告诉我没有结果。 我试图在 mysql table.

中找到全名如全名的所有用户

如果找到,回显用户个人资料图片 30x30 和他的名字链接到他的个人资料页面。

但它不起作用。希望得到一些帮助。

at first you have to change from mysql to mysqli


更改这部分代码

//define $i     
foreach($terms as $each){
            $i++; // increment at the end of each iteration  

        if($i == 1)
            $query .= "fullname LIKE '%$each%'";
        else
            $query .= "OR fullname LIKE '%$each%'";

   }  

并且您必须显示 sql 错误才能知道真正发生了什么

    $result = mysql_query($query) or die(mysql_error());;
    $numrows = mysql_num_rows($result);

这里

$id = $row['id'];
$fullname = $row['fullname']; 

只需更改此行即可解决您的问题。

$query .= " OR fullname LIKE '%$each%'";