Tony
Tony

Reputation: 298

How do I get my search results to display multiple returns across more than I row?

The search I have set up returns the results I want, but I can't get them to display across multiple rows when the search result returns more than I answer. I tried using a simple break to start a new row after each return but it didn't work. Any help will be greatly appreciated.

<?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>

Upvotes: 1

Views: 115

Answers (1)

Anton Todua
Anton Todua

Reputation: 687

Use <br> instead of simple line feed.

printf ("%s (%s)<br/>", $row[0], $row[1]);

Upvotes: 2

Related Questions