|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi
I have use the help on this site on, developing a site search engine with PHP and MYSQL by Mitchell Harper. I redo the scripts to do a search for books. The problem was that they is only one output result eventhough they should be two. so I took out the "$books = array_unique($books);" from the scripts and it shows the correct results. However if i were to put two keywords to search, i would get a duplicate. If I keep the "$books = array_unique($books);" it still does the duplicates when two or more keywords are entered. Could anyone help. Thanks. this is the codes --------------------------------------------------------------------------------- function doSearch($searchfield) { $arrWords = explode(" ", $searchfield); if(sizeof($arrWords) == 0 || $searchfield == "") { echo "You didn't enter any keywords<br>"; } else { // Connect to the database $conn = db_connect(); for($i = 0; $i < sizeof($arrWords); $i++) { $query = "select book_id from searchWords where word = '{$arrWords[$i]}'"; $result = mysql_query($query); if(mysql_num_rows($result) > 0) { // Get the id's of the articles $row = mysql_fetch_array($result); $arrIds = explode(",", $row[0]); $arrWhere = implode(" OR book_id = ", $arrIds); $aQuery = "select isbn, title, left(description, 100) as summary from books where book_id = " . $arrWhere; $aResult = mysql_query($aQuery); $count = 0; $books = array(); if(mysql_num_rows($aResult) > 0) { while($aRow = mysql_fetch_array($aResult)) { $books[$count] = array ("isbn" => $aRow["isbn"],"title" => $aRow["title"],"summary" => $aRow["summary"]); $count++; } } if(isset($books)) { //$books = array_unique($books); echo "<b>" . sizeof($books); echo (sizeof($books) == 1 ? " book" : " books"); echo " found:</b><br>"; foreach($books as $a => $value) { ?> <a href="show_book.php?isbn=<?php echo $books[$a]["isbn"]; ?>"> <b><u><?php echo $books[$a]["title"]; ?></u></b> </a> <br><?php echo $books[$a]["summary"] . "..."; ?> <br> <A class=NArialSG href="show_book.php?isbn=<?php echo $books[$a]["isbn"]; ?>"> Click to view book </a> <br><br> <?php } } }else { echo "No results found for '$searchfield'<br>"; } } } } ?> -------------------------------------------------------------------------------- MySQL searchWord table: 1. Macroeconomics Sixth Edition - assign keywords - economics 2. Essential Mathematics for economics & business 2E -assign keywords - economics, mathematics This is the output results if i were to put in two keywords to search.. keywords:economics mathematics 2 books found: Macroeconomics Sixth Edition The sixth edition is in the form of two books, Microeconomics and Macroeconomics, which, f... Click to view book Essential Mathematics for economics & business 2E Essential Mathematics for Economics and Business has become established as one of the leading introd... Click to view book 1 book found: Essential Mathematics for economics & business 2E Essential Mathematics for Economics and Business has become established as one of the leading introd... Click to view book ![]() Last edited by androolz : August 15th, 2002 at 12:47 AM. |
|
#2
|
|||
|
|||
|
try using the like command?? WHERE field LIKE '%$var%'
something like that Regards Ben Rowe |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Books site search has duplicates output |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|