我正在尝试为我的网页创建一个搜索功能,但我在格式化结果时遇到了困难,以便它以表格格式出现,这是我的代码:
<?php
$query = $_GET['query'];
$min_length = 10;
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 aggrement
WHERE (`description` LIKE '%".$query."%') OR (`start_date` LIKE '%".$query."%') OR (`end_date` LIKE '%".$query."%') OR (`balance` LIKE '%".$query."%') OR (`tax_value` LIKE '%".$query."%') OR (`amount_paid` LIKE '%".$query."%') OR (`hosting_name` LIKE '%".$query."%') OR (`domain_name` LIKE '%".$query."%') OR (`first_name` LIKE '%".$query."%') OR (`last_name` LIKE '%".$query."%')") or die(mysql_error());
if(mysql_num_rows($raw_results) > 0){
while($results = mysql_fetch_array($raw_results)){
echo "<p><h3>".$results['description']."</h3>".$results['start_date']."</p>";
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
}
?>
我正在使用 echo 输出结果 echo "<p><h3>".$results['description']."</h3>".$results['start_date']."</p>";
但我想使用这种语法:
echo "<table>";
echo "<tr>
<th>Id</th>
<th><a href='viewaggrement.php?sort=description'>Description</th>
<th><a href='viewaggrement.php?sort=start_date'>Start Date</th>
<th><a href='viewaggrement.php?sort=end_date'>End Date</th>
<th><a href='viewaggrement.php?sort=balance'>Balance</th>
<th><a href='viewaggrement.php?sort=tax_value'>Tax </th>
<th><a href='viewaggrement.php?sort=amount_paid'>Amount Paid</th>
<th><a href='viewaggrement.php?sort=domain_name'>Domain Name</th>
<th><a href='viewaggrement.php?sort=hosting_name'>Hosting Name</th>
<th><a href='viewaggrement.php?sort=first_name'>First Name</th>
<th><a href='viewaggrement.php?sort=last_name'>Last Name</th>
<th>Edit</th>
<th>Delete</th>
</tr>";
echo "<table>";