久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

突出顯示 php/mysql 中的搜索結果

highlighting search results in php/mysql(突出顯示 php/mysql 中的搜索結果)
本文介紹了突出顯示 php/mysql 中的搜索結果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何使用 php 突出顯示來自 mysql 查詢的搜索結果?

這是我的[修改]代碼:

$search_result = "";$search_result = $_GET["q"];$result = mysql_query('SELECT cQuotes, vAuthor, cArabic, vReference FROM thquotes WHERE cQuotes LIKE "%' . $search_result .'%" ORDER BY idQuotes DESC', $conn)或死('錯誤:'.mysql_error());函數 h($s) {echo htmlspecialchars($s, ENT_QUOTES);}?><div class="caption">搜索結果</div><div class="center_div"><表格><?php while ($row= mysql_fetch_array($result)) { ?><?php $cQuotes = preg_replace($search_result, "<div class='highlight'>".$search_result."</div>", $row['cQuotes']);?><tr><td style="text-align:right; font-size:15px;"><?php h($row['cArabic']) ?></td><td style="font-size:16px;"><?php h($cQuotes) ?></td><td style="font-size:12px;"><?php h($row['vAuthor']) ?></td><td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']) ?></td></tr><?php } ?>

解決方案

您可以使用 preg_replace();,當它在您的文本中找到匹配項時,您可以在匹配的單詞周圍放置一個帶有突出顯示類的 div.然后,您將向高亮類添加背景顏色和邊框以使其脫穎而出

preg_replace 需要 3 個參數;

  1. 第一個是您要查找的內容
  2. 第二個是應該改成什么
  3. 他應該搜索和替換的文本字符串

例如

<表格><caption>搜索結果</caption><?php while ($row= mysql_fetch_array($result)) { ?><?php $arabic = preg_replace("/".$search_result."/", "<div class='highlight'>".$search_result."</div>", h($row['阿拉伯語']));?><tr><td style="text-align:right; font-size:15px;"><?php $arabic ?></td><td style="font-size:16px;"><?php h($row['cQuotes']) ?></td><td style="font-size:12px;"><?php h($row['vAuthor']) ?></td><td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']) ?></td></tr><?php } ?>

我只為阿拉伯語做了這件事,但您可能也需要為 cQuotes、vAuthor 和 vReference 這樣做.

how do i highlight search results from mysql query using php?

this is my [modified] code:

$search_result = "";

$search_result = $_GET["q"];

$result = mysql_query('SELECT cQuotes, vAuthor, cArabic, vReference FROM thquotes WHERE cQuotes LIKE "%' . $search_result .'%" ORDER BY idQuotes DESC', $conn)
  or die ('Error: '.mysql_error());


function h($s) {
    echo htmlspecialchars($s, ENT_QUOTES);
} 


?>

    <div class="caption">Search Results</div>
<div class="center_div">
<table>
    <?php while ($row= mysql_fetch_array($result)) { ?>
    <?php $cQuotes = preg_replace($search_result, "<div class='highlight'>".$search_result."</div>", $row['cQuotes']); ?>
        <tr>
            <td style="text-align:right; font-size:15px;"><?php h($row['cArabic']) ?></td>
            <td style="font-size:16px;"><?php h($cQuotes) ?></td>
            <td style="font-size:12px;"><?php h($row['vAuthor']) ?></td>
            <td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']) ?></td>
        </tr>
    <?php } ?>
</table>
</div>

解決方案

you could use preg_replace();, when it finds a match in your text you could place a div with a class of highlight around the matching word. You would then add a background color and border to the highlight class to make it stand out

preg_replace expect 3 parameters;

  1. the first one is what you are looking for
  2. second one is what should it be changed to
  3. The string of text he should search and replace from

so for example

<div class="center_div">
    <table>
    <caption>Search Results</caption>
    <?php while ($row= mysql_fetch_array($result)) { ?>
<?php $arabic = preg_replace("/".$search_result."/", "<div class='highlight'>".$search_result."</div>", h($row['cArabic'])); ?>
            <tr>
                <td style="text-align:right; font-size:15px;"><?php $arabic ?></td>
                <td style="font-size:16px;"><?php h($row['cQuotes']) ?></td>
                <td style="font-size:12px;"><?php h($row['vAuthor']) ?></td>
                <td style="font-size:12px; font-style:italic; text-align:right;"><?php h($row['vReference']) ?></td>
            </tr>
        <?php } ?>
    </table>
    </div>

I only did it for arabic but you might need to do that for cQuotes, vAuthor and vReference as well.

這篇關于突出顯示 php/mysql 中的搜索結果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 久久亚洲国产精品 | 欧美日韩国产在线观看 | 日韩欧美中文字幕在线视频 | 欧美高清hd | japanhd美女动| 亚洲国产成人久久综合一区,久久久国产99 | 国产精品成人在线播放 | 欧美日韩专区 | 国产精品毛片久久久久久 | 久久精品久久久 | 亚洲精品久久久久久久久久久 | 国产一区二| 99这里只有精品视频 | 亚洲综合一区二区三区 | 日韩第1页| 国产精品69久久久久水密桃 | 日日摸日日添日日躁av | 91毛片在线看 | 天天草天天 | 五月天婷婷丁香 | 久久6视频| 91免费看片 | 国产成人区| 欧美伊人久久久久久久久影院 | 国产精品美女久久久免费 | 欧美一区二不卡视频 | 亚洲高清在线观看 | 日韩久久久久久 | 国产精品久久久久久久久久99 | 久久精品亚洲精品国产欧美 | 欧美1区2区 | 久久lu| 国产蜜臀 | 欧美a在线看 | 一区二区在线看 | 午夜激情免费 | 国产高清一区二区三区 | 欧美一级二级视频 | 亚洲欧洲中文日韩 | 一区二区三区高清在线观看 | 91九色网站|