Skip navigation links

MySQL Forums :: PHP :: Display search results in table


Advanced Search

Display search results in table
Posted by: Jo Miles-Seely ()
Date: April 05, 2010 02:18PM

I have created a script that searches all 3 fields of a MySQL database and returns the results of 2 of the columns on a web page. I want the rows returned to display in a form with the columns of each row side-by-side. I've never done this before. Samples I find on the web are confusing because I'm not finding a script that is similar to how I've written mine. Can someone please help me take what I've got and create what I want? I understand that I need to create an html table, but, I don't know where to put it or how to get my data into it. Below is my script. Thanks.

<html>
<head>
<title>Title Goes Here</title>
</head>
<body>
<h2>Heading Goes Here</h2>

<?php
$search_term = $_POST['searchterm'];

$dbc = mysqli_connect('localhost', 'username', 'password', 'database') or die ('Cannot connect to database');
$query = "SELECT * FROM subject WHERE title LIKE '%$search_term%' || subject LIKE '%$search_term%' || keyword LIKE '%$search_term%'";

$result = mysqli_query($dbc, $query) or die('Cannot execute query');
$num=mysqli_num_rows($result);
mysqli_close($dbc);

echo 'Your search term ' . $search_term . 'produced the following results: <br /><br />';

$i=0;
while ($i < $num) {
$row-mysqli_fetch_assoc($result);
$title=$row["title"];
$subject=$row["subject"];
$keyword=$row["keyword"];

echo $title;
echo $subject;

$i++;
}
?>

</body>
</html>

Options: ReplyQuote


Subject Written By Posted
Display search results in table Jo Miles-Seely 04/05/2010 02:18PM
Re: Display search results in table Guelphdad Lake 04/05/2010 02:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.