I am trying to display various types of search results on a seperate page:

Here is my PHP CODE for the form:


<table width="75%" cellspacing="10" cellpadding="10">
      <td width="22%" class="subtiwhite"><strong>Search by Name:</strong></td>
      <td width="74%"><form name="form1" method="get" action="searchname.php">
        <input type="text" name="namelist" id="namelist">
        <input type="submit" name="searchname" id="searchname" value="Submit">
      <td width="4%"> </td>
      <td class="subtiwhite"><strong>Search by Country:</strong></td>
      <td><form name="form2" method="post" action="searchcountry.php">
        <select name="countrylist" id="countrylist" class="list">
          <option value="" selected>COUNTRIES</option>
          <option value="AFGHANISTAN">Afghanistan</option>
          <option value="ALBANIA">Albania</option>
          <option value="ALGERIA">Algeria</option>
        <input type="submit" name="searchcountry" id="searchcountry" value="Submit">
      <td> </td>
      <td><strong class="subtiwhite">Search by Keywords*:</strong></td>
      <form name="form4" method="post" action="searchkeywords.php">
      <td><input name="keyword1" type="text" id="keyword1" value="1st Keyword" size="18" maxlength="20">
        <strong>        +</strong>
<input name="keywords2" type="text" id="keywords2" value="2nd Keyword" size="18" maxlength="20">
<strong>        + </strong>
<input name="keywords3" type="text" id="keywords3" value="3rd Keyword" size="18" maxlength="20">
<input type="submit" name="searchkeywords" id="searchkeywords" value="Submit"></td>
      <td> </td>
      <td>* Note:</td>
      <td>You can use just one keyword or up to a combination of 3 keywords for more accurate results.</td>
      <td> </td>


What would be the correct script to use so all matching values found from the specific table in the database can be displayed in a table (one line per each different row) based on:

Search by name: (complete or even partial)
Search by country: (from a drop down list)
Search by a combination of up to 3 keywords (3 values from 3 textfield)

For example if I search by name:

I enter name: "cat" I will have on the result page a table with all datas that conatains cat sorted by ID

cat www.cat.com 01.01.12 description of website here
super cat www.supercat.com 01.05.12 description of website here
catnmouse www.catnmouse.com 03.06.12 description of website here

Thank you for your help!

If you want to direct to another page for displaying the results then you use the form to post the inputs to the next page (searchname.php as your form is currently set up) and that page then reads them out of the POST data and executes the retrieval from the database.
The script to use is the basic SQL SELECT statement:
SELECT coulumn_name, column_name... FROM table_name WHERE matching_criteria

For your partial search you would use the LIKE condition in the WHERE clause e.g.

SELECT name FROM some_table WHERE name LIKE '%cat%';

The % signs indicate whether you want to the search term (cat in the example) to be at the start, end or anywhere in the searched text. 'cat%' means it must start with cat while '%cat' means it must end in cat to be selected.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.