-4

I am Front end developer but never touched any backend language. So now I have to create a website for my client. They have supposed data of 500 items with 10 fields each in Excel file. Now they want to create a search engine within their website where we search for the name and all the info related to that name appears.Search should be only by 1 field that is name. Any help? Even if I hire someone to help me out, what all technologies he/she should know?

Taron
  • 1
  • 1
  • This page will give you some ideas: https://stackoverflow.com/questions/21386497/javascript-search-engine-search-own-site –  Sep 15 '17 at 06:41
  • Define "search". Exact match? Google-like? Spelling corrector? Etc. – Rick James Sep 15 '17 at 19:50

3 Answers3

0

Dont think its right thing to do. Using database would be a good idea but this is something you can do to overcome this issue.I think import your data to html table and do the following.

function myFunction() {
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");

  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[0];
    if (td) {
      if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}
#myInput {
    background-image: url('/css/searchicon.png'); 
    background-position: 10px 12px; 
    background-repeat: no-repeat;
    width: 100%;
    font-size: 16px;
    padding: 12px 20px 12px 40px; 
    border: 1px solid #ddd; 
    margin-bottom: 12px;
}

#myTable {
    border-collapse: collapse;
    width: 100%;
    border: 1px solid #ddd;
    font-size: 18px;
}

#myTable th, #myTable td {
    text-align: left;
    padding: 12px; 
}

#myTable tr {
    border-bottom: 1px solid #ddd; 
}

#myTable tr.header, #myTable tr:hover {
    background-color: #f1f1f1;
}
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">

<table id="myTable">
  <tr class="header">
    <th style="width:60%;">Name</th>
    <th style="width:40%;">Country</th>
  </tr>
  <tr>
    <td>Garry</td>
    <td>Australia</td>
  </tr>
  <tr>
    <td>Ben Hopkins</td>
    <td>USA</td>
  </tr>
  <tr>
    <td>Deric</td>
    <td>UK</td>
  </tr>
  <tr>
    <td>Ollie</td>
    <td>Germany</td>
  </tr>
</table>
usrNotFound
  • 2,680
  • 3
  • 25
  • 41
  • I have 1 more question, I don't want the table to be shown all the time here. Rather I would like it to be hidden. So should I put "display: hidden" for the table? – Taron Sep 15 '17 at 07:01
-1

First of all, You need a DBMS in you PC then make a Database here according to requirements. then using server side programming language like PHP, C#, Java etc. now you are able to make the search engine. I am here to help you more if you need more help. thanks

TouchStarDev
  • 421
  • 2
  • 7
  • 19
-2

Here are dome steps that might help you 1. You need a database and all the data inserted to it with specific fields. 2. Now On the front-end you need a from like this

<form method="post" action="">
<input type = text name="field_name_to_search">
<input type = submit name = "submit" value="submit" >
</form>

3. For displaying the data searched you need a database connection for the file in which you are writing your code. 4. After connecting with database you need to get the data with sql query and view in a required format. The query can be like this

<?php if(isset($_POST('submit'))){

    $sql = "select * from database_table WHERE field_name_to_search = 
        $_POST('field_name_to_search')";
}
 ?>

5. Now you have all the data regarding the field searched in the variable $sql. 6. You can check the data by print_r($sql) function. You have all the data that is searched you can parse it into your html using a (for) loop.

If you hire a developer just show him this answer. I am sure he will get my point.

  • Please do not suggest using unchecked, unsterilized input variables - especially not directly to a database / SQL query. That is just asking for SQL injection among other security issues. – Jim Sep 16 '17 at 16:15