I'm trying to add a search function to my website, and I'm not real sure how to go about it. I have a loaded database on my site with the following fields:
id //(primary key)
title //(image title)
page //(name of the page the image is on)
thumb //(name of the thumbnail image)
kywords //(keywords that describe the image)
The kywords field has many keywords separated by commas. I used commas to prevent the end of one word and the beginning of the next from accidentally giving a false match.
I have a form set up that a user can enter a keyword in. When they hit submit, I would like for it to pull all entries from the database, keeping all of the info for each image related to each other. Then I want it to compare the user entry to the kywords field & select all matches and display the thumbnails & titles as clickable links in a table with 4 columns across. If there is not enough to fill the row, I want it to just display blank space with no link.
My form code is:
<form action="../php/redirect17.php" method="post">
<table width="50%">
<tr>
<td width="33%" align="right">Enter Search Term:</td>
<td width="25%" align="left"><input type="text" name="look" SIZE="10" /></td>
<td width="42%" align="left"><input type="submit" value="Search" name="search" /></td>
</tr>
</table></form>
What I have so far for redirect17.php is:
<?php
if(isset($_POST['search'])){
$look=$_POST['look'];
// Set Mysql Variables
$host='xxxxxxx';
$user='xxxxxxx';
$pass='xxxxxxx';
$db='xxxxxxxx';
$table='xxxxxxxx';
unset($name, $title, $pic, $thumb, $kywords);
// Connect to Mysql, select the correct database
mysql_connect($host, $user, $pass) or die('Connection died!');
mysql_select_db($db) or die('Selection died!');
I'm stuck after this... Any ideas?