我正在使用此代码搜索我的sql数据库,它可以正常工作,但如果有多个结果,它只会在每个结果旁边显示
示例:
echo "".$row['nick'].""; //would be NAME1NAME2NAME3NAME4
我想显示
NAME1
MORE INFO
NAME2
MORE INFO
NAME3
MORE INFO
<?php
$conn = mysql_connect ("*****", "battlefield", "*****") or die ('I
cannot connect to the database because: ' . mysql_error());
$selected = mysql_select_db ("battlefield")
or die ("Could not select database");
// PHP Search Script
$sql = "SELECT * FROM loadout WHERE nick LIKE '%".$_POST['find']."%'";
$result = mysql_query($sql,$conn)or die (mysql_error());
if (mysql_num_rows($result)==0){
echo "Theres no one here called that!";
}else{
while ($row = mysql_fetch_array($result)){
echo "".$row['nick']."";
}
}
mysql_close();
?>
如果您需要html或更多信息,请询问xD
提前致谢!
答案 0 :(得分:0)
只需添加<br>
:)!
while ($row = mysql_fetch_array($result)){
echo "".$row['nick']." <a href='link'>MORE INFO</a><br>";
}
或者,如果您想在页面的其他位置显示它,请将所有结果添加到ann数组中,然后在任意位置迭代它们:
存储它们:
while ($row = mysql_fetch_array($result)){
$results[] = $row['nick']." <a href='link'>MORE INFO</a><br>";
}
显示它们:
foreach ($results as $result) {
echo $result;
}