Я знаю html и очень мало чего еще.
Я пытаюсь собрать простую поисковую систему для моего сайта. У меня есть 3 таблицы, которые я хочу присоединиться, а затем есть данные, доступные для поиска.
MESSAGES (ID_TOPIC, SUBJECT)
TAGS (ID_TAG, TAG)
TAGS_LOG (ID_TAG, ID_TOPIC)
Я пытаюсь создать массив с тремя таблицами (MESSAGES, TAGS и TAGS_LOG), чтобы я мог создать поисковую систему, которая выполняет поиск TAGS и выводит данные с помощью MESSAGES.SUBJECT в качестве гиперссылки, где HYPERLINK - www.website .com / ID_TOPIC
Я осмотрелся и подошел близко, но денег нет.
Пока у меня есть;
CREATE TABLE new_table
AS (SELECT tags.id_tag, messages.subject, tags.tag, tags_log.id_topic
FROM messages, tags, tags_log);
, который работает для объединения информации в одну таблицу для поиска. Затем я создал search.php;
<h2>Search</h2>
<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="tag">tag</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
<?
$field = $_POST['field'] ;
$find = $_POST['find'] ;
$searching = $_POST['searching'] ;
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
// Otherwise we connect to our Database
mysql_connect("host", "user", "pass") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM new_table WHERE upper($field) LIKE'%$find%'");
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo " ";
echo "Topic ID: {$result['id_topic']}";
echo "<br>";
Print "<a href=/index.php?topic={$result['id_topic']} target=new>{$result['subject']} </a>";
echo "<br>";
echo "<br>";
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>
Но у меня проблемы с дуплексами, как и в Subject, я получаю результаты от Subject и RE: Subject. Я не уверен, как отсеять «RE: Subject», чтобы не было повторяющихся записей.