開啓新的話題,因爲得到了進展,現在需要更多的幫助。搜索欄找到用戶
我已經創建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表中的所有用戶。
如果找到,請回複用戶個人資料圖片30x30和他的姓名鏈接到他的個人資料頁面。
但它不起作用。希望得到一些幫助。
是否報告了任何錯誤?您是否輸出了查詢並查看了正在構建的內容?您應該首先定義'$ i',並在每次迭代結束時增加它。這也將爲您打開SQL注入。您應該切換到'mysqli'或'pdo'並使用預準備語句。 – chris85
@ chris85什麼也沒有,它就像numrows = 0並轉到else函數並且不打印任何結果。 –
在$ query = mysql_query($ query)之前;輸出查詢。嘗試在db上運行。 – chris85