Hello again,
I’ve created a search form but for some reason it’s only working on one field not the other. Search process looks like this.
mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name);
$search_term = $_POST['search_term'];
$sql_1 = mysql_query("SELECT DISTINCT info.scheme_id, info.scheme_title FROM (info, tags) WHERE info.scheme_title LIKE '%$search_term%' OR tags.tag_name LIKE '%$search_term%'");
$result_num = mysql_num_rows($sql_1);
echo "<p>Search found $result_num results.</p>";
while($row = mysql_fetch_array($sql_1)){
echo "<h3>" . $row['scheme_title'] . "</h3>";
echo "<p>";
$hex_values = mysql_query("SELECT hex_value FROM colours WHERE scheme_id=" . $row['scheme_id']);
$number_colour = mysql_num_rows($hex_values);
$nc = 1;
while ($colour = mysql_fetch_array($hex_values)){
echo "#".$colour['hex_value'];
if($nc < $number_colour){
echo " - ";
$nc++;
}
}
echo "</p>";
$values = mysql_query("SELECT hex_value FROM colours WHERE scheme_id=" . $row['scheme_id']);
while ($colours = mysql_fetch_array($values)){
echo "<img src='images/colour_box.png' style='background-color: #".$colours['hex_value']."' />";
}
$tags = mysql_query("SELECT tag_name FROM tags JOIN scheme_tags USING ( tag_name ) WHERE scheme_id=".$row['scheme_id']);
$number_tags = mysql_num_rows($tags);
$nt = 1;
echo "<p>";
while ($tag = mysql_fetch_array ($tags)){
echo $tag['tag_name'];
if($nt < $number_tags){
echo ", ";
$nt++;
}
}
echo "</p>";
}
It doesn’t work with the tag_name, when you search for a tag it displays all records in the database
Any thoughts?
Thanks,
Steph.