私はhtmlを知っていて、他の何ものもほとんどありません。SQL Search Engine
私は自分のウェブサイトに簡単な検索エンジンを組み込もうとしています。私はJOINしたい3つのテーブルを持っているし、検索可能なデータを持っている。
MESSAGES (ID_TOPIC, SUBJECT)
TAGS (ID_TAG, TAG)
TAGS_LOG (ID_TAG, ID_TOPIC)
私は3つのテーブル(メッセージ、タグ、およびTAGS_LOG)を持つ配列を作成しようとしているので、私はハイパーリンクハイパーリンクとしてMESSAGES.SUBJECTでデータをTAGSを検索して出力する検索エンジンを作成することができます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);
情報を1つのテーブルにまとめて検索する機能を果たします。次に、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;
}
?>
しかし、私は、件名のようにdupesの問題を抱えている、私は、件名とREの結果を取得しています:件名を。私は "RE:Subject"を取り除く方法がわからないので、重複するエントリーはありません。
かなり広い質問です。あなたがやったこととどこにいるのかを含めるようにしてください。 – Randy
質問は何ですか? –
あなたは "まったく見た"と言いますが、 "sql join tutorial"をgooggledしていますか? SQLの基本を学び、あなた自身の質問に答えることができます。 – Tony