Search DataBase using PHP -


I am trying to show the highlighted word in red to a user when a user searches for a name in the database , Here's the code: echo "& lt; table class = 'name list' & gt;"; Echo "& lt; tr & gt; & lt; h3 & gt; You searched for & lt; Span class = 'Red' & gt; $ query & lt; / span & gt; ... please find the details . & Lt; / h3 & gt; & lt; / tr & gt; "; Echo "<<<< gt >> United Nations Full Name & lt; / tr & gt; "; $ Result = mysql_query (Select "United Nations, NAME mytable from WHERE ('%.' $ Query"% 'like' NAME ') ") or die (mysql_error ()); if (mysql_num_rows ($ result)> gt; ; 0) {While ($ result = mysql_fetch_array ($ result)) {resonant "& lt; Tr & gt; & Lt; Td> ". $ Result ['United Nations]]." & Lt; / Td> & Lt; TD & gt; & Lt "$ result ['name'] .."; / TD & gt; & Lt; / TR & gt; & Lt; span class = 'red' & gt; $ query & lt; / span & gt; Try Again! & Lt; / td> & lt;; & lt; ; Tr & gt; "; Echo "& lt; / table & gt;";

before you can use the process on results When the result comes from the database, you will need to find your query in the result and replace it with the span which is red or what you want. In the example I have the background-color = yellow; , you can call it color = red;

  // Create a function, highlight a list of words in the string. Function Highlight Words ($ string, $ word) {// One word foreach ($ word as word $ word) {// foreign word keyword as word} and replace it with background color = yellow, if you want Then change it to red color, $ string = str_ireplace ($ word, '& lt; span style = "background-color: yellow" & gt;'. $ Word. '& Lt; / span & gt;', $ string ); } // Return string return $ string; } // Specify the words that you are looking for for $ word = array ("zebra"); // Your String $ string = "My name Zebra, Will Zebra do this?"; // Highlight $ string = highlightwords ($ string, $ word); // echo $ string;   

Here is the result:

Enter image details here

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -