Hi people,
this is my first post on this forum. I use this occasion to say hello to all 🙂
I have a question about php and mysql:
I created a simple search engine
<form action = '#' method = 'post'>
<input type = 'text' name = 'key' value = ''>
<input type = 'submit' value = 'Search' class = 'submit'>
</form>
When I press the "Search" button, it reloads the same page and execute a sql query in a database that contains informations about computers:
$search_sql = mysql_query("SELECT ip FROM My_Table WHERE
(ip LIKE '%" . $key . "%') OR (cpu LIKE '%" . $key . "%') OR (ram LIKE '%" . $key . "%') OR ... ORDER BY name");
In the previous code I put "..." to avoid a long list of query conditions.
After the query execution I print the number of occurrences with this code:
$found = mysql_num_rows($search_sql);
if($found > 0){
echo "<p>Found $found occurrences";
}else{
echo "<p>no matches found!";
}
It works but my question is:
It's possible to get the column name(s) where my search term is present?
example:
search -> Intel Xeon
real result -> Found 10 occurrences
desired result -> Found 10 occurrences in CPU column
I hope I was clear and apologize for my bad english, it's not my motherlanguage 😃
Thank you in advance.