I created search function. After searching the results it displayed to another page and it was succeed. I had a 2 results and displayed to table. The problem is those 2 results were displayed into two tables. I want to make it as 1 table and inside of that table is the result (s).
These are the codes.
<?php
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do
following
while($results = mysql_fetch_array($raw_results)){
echo "<div id= 'table_wrapper'>";
echo "<table border='1' style='border: 1px solid black;'>";
echo "<tr>";
echo "<th> ID: </th>";
...
echo "</tr>";
echo "<tr>";
echo "<td>" .$results['id']."</td>";
...
echo "</tr>";
echo "</table>";}}
else{ // if there is no matching rows do following
echo "No results";}}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;}
?>
I FINALLY GOT THE ANSWER!
**NOTE: THIS IS THE CORRECT ANSWER TO MY QUESTION:** *And its totally working as I
wanted.*
<table>
<tr>
<th> ID: </th>
...
</tr>
<?php
//other php code here ...
<?php
//other php code here ...
echo "<tr>";
echo "<td>" .$results['id']."</td>";
...
echo "</tr>";}}
else{ // if there is no matching rows do following
echo "No results";}}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;}
?>
</table>
Change your code like this.
Take table out of your loop.
<?php
$query = $_GET['query'];
$min_length = "";
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query("SELECT * FROM tqA
WHERE (`date_now` LIKE '%".$query."%') OR (`first_name` LIKE '%".$query."%') OR (`last_name` LIKE '%".$query."%') OR (`job_title` LIKE '%".$query."%') OR (`department` LIKE '%".$query."%') OR (`company_name` LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
echo "<div id= 'table_wrapper'>";
echo "<table border='1' style='border: 1px solid black;'>";
echo "<tr>";
echo "<th> ID: </th>";
echo "<th> Firstname: </th>";
echo "<th> Last name: </th>";
echo "<th> Job title: </th>";
echo "<th> Department: </th>";
echo "<th> Email address: </th>";
echo "<th> Contact number: </th>";
echo "<th> Company Name: </th>";
echo "</tr>";
while($results = mysql_fetch_array($raw_results)){
echo "<tr>";
echo "<td>" .$results['id']."</td>";
echo "<td>" .$results['date_now']."</td> ";
echo "<td>" .$results['first_name']."</td> ";
echo "<td>" .$results['last_name']."</td> ";
echo "<td>" .$results['department']."</td> ";
echo "<td>" .$results['email_address']."</td> ";
echo "<td>" .$results['phone_cell']."</td> ";
echo "<td>" .$results['company_name']."</td> ";
echo "</tr>";
}
echo "</table>";
}
else{ // if there is no matching rows do following
echo "No results";}}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;}
?>