簡體   English   中英

顯示來自mysql的搜索結果

[英]Displaying search results from mysql

我將在下面粘貼我的PHP代碼。 我有4個以Web開發人員為職的職位。 我本質上希望它將它們打印在一個有組織的表中。

<?php
include_once 'header.php';

$output="";
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);

$query = mysql_query("SELECT * FROM job,address WHERE title LIKE '%$searchq%' or cname     LIKE '%$searchq%'") or die("could not search");
$count = mysql_num_rows($query);

$pageTitle="Search Results";

if($count == 0){
    $output = 'There are no results';   
}else{
    while ($row = mysql_fetch_array($query)){
            $cname=$row["cname"];
            $title=$row["title"];

            $output .= '<div id="field">'.
                        '<h2> Search Results</h2>'.
                        '<h3><strong>'.$count.'</strong> results found searching for <strong>'."$searchq".'</strong></h3>'.

                        '<table cellpadding="5">'.
                            '<tr>'.
                            '<th> Company Name </th>'.
                            '<th><strong> Position Title </th>'.
                            '</tr>'.
                            '<td>'. $cname.' </td>'.
                            '<td>'. $title .'</td>'.
                            '<td> <button onclick="myFunction()"> Location </button> </td>'.
                            '</tr>'.
                        '</table>'.

                        '</div>';

    }
}
}
?>

我不想復制並粘貼整個內容。 但是在我打印“ $ output”的底部只是:

<?php
print ("$output$");
?>

編輯:我在PHP上還很新,所以這可能不是最好的方法。 (這不是一個專業站點。這只是一個學校項目。)

屏幕截圖:

由於某種原因,地圖掩蓋了其余信息。 所以我刪除了地圖,這就是結果。

在此處輸入圖片說明

您缺少<tr>標記

  '<table cellpadding="5">'.
   '<tr>'.
    '<th> Company Name </th>'.
    '<th><strong> Position Title </th>'.
    '</tr>'.
    '<td>'. $cname.' </td>'.    //<---- here
    '<td>'. $title .'</td>'.
    '<td> <button onclick="myFunction()"> Location </button> </td>'.
    '</tr>'.
'</table>'.

您是否真的要為每個結果打印整個表格?

可能只是

    '<tr>'.
    '<td>'. $cname.' </td>'.   
    '<td>'. $title .'</td>'.
    '<td> <button onclick="myFunction()"> Location </button> </td>'.
    '</tr>';

應該在while循環中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM