我设置的搜索会返回我想要的结果,但是当搜索结果返回的次数超过我的答案时,我无法让它们显示在多行中。我尝试使用一个简单的中断在每次返回后开始一个新行,但它不起作用。任何帮助将不胜感激。
<?php
$servername = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "oldga740_SeniorProject";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// If there is a search variable try to search database
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$sql = "SELECT * FROM Customers WHERE Client LIKE '%$searchq%'";
if ($result = mysqli_query($conn, $sql)) {
/* fetch associative array */
while ($row = mysqli_fetch_row($result)) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
/* free result set */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($conn);
}
?>
<html>
<head>
</head>
<body>
<form action="Index.php" method="post">
<input type="text" name="search" placeholder="Search...." />
<input type="submit" value=">>" />
</form>
</body>
</html>
答案 0 :(得分:2)
使用&lt; br&gt;而不是简单的换行。
printf ("%s (%s)<br/>", $row[0], $row[1]);