General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 15th, 2002, 12:44 AM
androolz androolz is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 1 androolz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Books site search has duplicates output

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.

Reply With Quote
  #2  
Old August 15th, 2002, 12:47 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
try using the like command?? WHERE field LIKE '%$var%'


something like that

Regards
Ben Rowe

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Books site search has duplicates output


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway