Highlight search term in mysql php search

前端 未结 3 459
借酒劲吻你
借酒劲吻你 2020-12-18 16:04

Could someone please help me to highlight the searchterm in my php search code? Below is the code that I am currently using, and it works fine. Would just like to add a high

3条回答
  •  难免孤独
    2020-12-18 16:13

    The simplest solution is to use str_replace() to replace the search term with tags wrapped around them, styled.

    Warning: The way you have your script set up, you're vulnerable to injection attacks. This is just an example to show you how to pass in variables.

    See: How can I prevent SQL injection in PHP?

    ";
    echo "

    "; echo ""; echo "

    "; echo "

    Your search has found "; echo "$num_rows"; echo " records.

    "; echo "

    "; echo ""; while($row = mysql_fetch_array($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
    Signed in By Reference Number Asset Number Make Model Serial Number Operating System Office Profile Extra Apps Time IN Status Time OUT
    " . str_replace($term, "$term", $row['who']) . "" . str_replace($term, "$term", $row['ref']) . "" . str_replace($term, "$term", $row['asset']) . "" . str_replace($term, "$term", $row['make_model']) . "" . str_replace($term, "$term", $row['serial']) . "" . str_replace($term, "$term", $row['os']) . "" . str_replace($term, "$term", $row['office']) . "" . str_replace($term, "$term", $row['swp']) . "" . str_replace($term, "$term", $row['ea']) . "" . str_replace($term, "$term", $row['dt_in']) . "" . str_replace($term, "$term", $row['status']) . "" . str_replace($term, "$term", $row['dt_out']) . "
    "; echo "

    "; echo ""; mysql_close($con); ?>

    And some sample styling:

    
    

提交回复
热议问题