我的搜索功能PHP搜索引擎
<?php
$i=0;
$column_name = 'title'; // column to search by
$k =$_GET['k'];
$terms = explode(" ",$k);
//connect before calling mysql_real_escape_string
mysql_connect("localhost","","");
mysql_select_db("test");
$query ="SELECT bookid,title,author
FROM books WHERE";
foreach ($terms as $each){
$i++;
$each = '%' . $each . '%'; // add wildcard
$each = mysql_real_escape_string($each); // prevent sql injection
if($i==1)
$query .= " $column_name LIKE '$each' ";
else
$query .= " OR $column_name LIKE '$each' ";
}
echo 'QUERY: ' . $query;
$query = mysql_query($query) OR DIE(mysql_error());
//Code below is for using the relationships table assuming you have a column name id that
//references to the relationships table. Also, you should add a index on the column id.
$results = "";
while($row = mysql_fetch_array($query)) {
$results .= '<li>
<a href="book-relationships.php?id='.$row['id'].'">'.$row['title'].' author: '.$row['author'].'</a>
</li>';
}
$results = '<ul>' . $results . '</ul>';
echo $results;
我需要幫助連接一個數據庫與其他搜索時,此數據庫列出所有都拿出了在搜索圖書,然後將它們與其他表進行比較,稱爲關係並打印出與搜索到的書籍有關係的書籍的標題。
當搜索運行這是在瀏覽器中
QUERY: SELECT id,title,author FROM books WHERE title LIKE '%jarrads%' Unknown column 'id' in 'field list'
任何helpy,將不勝感激產生我100%粘
模式
書籍 - BOOKID,標題,作者,年出版,出版者..... 關係 - relationshipid,bookOne,bookTwo,relationship,relationshiplikes,relationsdislikes
bookOne和bookTwo,涉及到BOOKID
你能與架構你的書籍表更新您的文章? –
您需要告訴我們表的數據庫模式是什麼樣子。 – Jeshurun
你可以發表你的表'書'的列 –