I have entered data into my table and now I want to retrieve it via a search engine on my site:
fourwaysdp.co.uk/seaside.php
I have two search boxes because I want to only retrieve rows that match the search terms.
I want each search box to represent each column in my table.
At the moment if i search: 'trainee' in one box and 'london' in the other all rows with trainee are displayed even if they do not have london in the row.
Here is the code:
Expand|Select|Wrap|Line Numbers
- <form action="seaside.php" method="post">
- <input type="text" name="search">
- <input type="text" name="search2">
- <input type="submit">
- </form>
- <hr width="100%"></hr>
- <?php
- if(strlen(trim($_POST['search'])) > 0) {
- //all of your php code for the search
- $search = "%" . $_POST["search"] . "%";
- mysql_connect ("", "", "");
- mysql_select_db ("");
- if (!empty($_POST["search_string"]))
- {
- }
- $query = "SELECT name,location,msg FROM contact WHERE name LIKE '$search'";
- $result = mysql_query ($query);
- if ($result) {
- while ($row = mysql_fetch_assoc($result)) {
- echo "{$row['name']}<br>".
- "{$row['location']}<br>".
- "{$row['msg']}<br>";
- }
- }
- }
- ?>
- </body>
- </html>
James