Jump to content
xisto Community
Sign in to follow this  

Php/mysql Search Engine Help Having issues displaying results

Recommended Posts

I've been using a tutorial (https://www.devarticles.com/c/a/MySQL/Developing-A-Site-Search-Engine-With-PHP-And-MySQL/)
at this address to help me get started on building my own search engine. I've completed the tutorial but when I run the search, I get no results on the results page. I'm wondering if anyone will take a look at this script and see if they can figure out why my I'm not getting any results displayed. I'm using phpMyAdmin to build the database and simple notepad to build the PHP script.

<?php$submit = $_POST["submit"];$keywords = $_POST["keywords"];if(isset($submit) || isset($keywords)){doSearch($keywords);}else{getKeywords();}function getKeywords(){?><html><head><title> Enter Search Keywords </title></head><body bgcolor="#FFFFFF"><form name="frmKW" action="searchdocs.php" method="post"><h1>Keyword Search</h1>Enter keywords to search on:<input type="text" name="keywords" maxlength="100"><br><br><input type="submit" name="submit" value="Search"></form></body></html><?php}function doSearch($search_keywords){$arrWords = explode("", $search_keywords);if(sizeof($arrWords) == 0 || $search_keywords == ""){echo "You didn't enter any keywords<br>";echo "<a href='searchdocs.php'>Go Back</a>";}{// Connect to the database$dServer = "localhost";$dDb = "content";$dUser = "x";$dPass = "x";$s = @mysql_connect($dServer, $dUser, $dPass)or die("Couldn't connect to database server");@mysql_select_db($dDb, $s)or die("Couldn't connect to database");for($i = 0; $i < sizeof($arrWords); $i++){$aQuery = "select articleId, title, left(content, 100) as summary from articles where articleId = " . $arrWhere;$aResult = mysql_query($aQuery); $count = 0;$articles = array();if(mysql_num_rows($aResult) > 0){while($aRow = mysql_fetch_array($aResult)){$articles[$count] = array ("articleId" => $aRow["articleId"],"title" => $aRow["title"],"content" => $aRow["content"]);$count++;}}$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 articleId = ", $arrIds);echo "<h1>" . sizeof($articles);echo (sizeof($articles) == 1 ? " article" : " articles");echo " found:</h1>";foreach($articles as $a => $value){?><a href="article.php?articleId=<?php echo $articles[$a]["articleId"]; ?>"><b><u><?php echo $articles[$a]["title"]; ?></u></b></a><br><?php echo $articles[$a]["summary"] . "..."; ?><br><a href="article.php?articleId=<?php echo $articles[$a]; ?>">[url=http://forums.xisto.com/no_longer_exists/; echo $articles[$a]["articleId"]; ?></a><br><br><?php}}else{echo "No results found for '$search_keywords'<br>";echo "<a href='searchdocs.php'>Go Back</a>";}}}}?>

The database has 2 tables (articles and searchWords) with 3 fields each ((ArticleID, title, content) and (WordID, Word and ArticleIDs). Each table has 2 records

I know this is a long script and this post maybe asking a lot, but I've gone over the tutorial several times and can't seem to indentify the difference in either my database structure or my PHP script.

All help is appreciated as well as more tutorials for building a MySQL/PHP driven search engine, if anyone knows any. Thank you.

Notice from snlildude87:
50% OF YOUR POST WAS CODE!! Use the code box whenever posting code.

*Edited and warned.*

Edited by snlildude87 (see edit history)

Share this post

Link to post
Share on other sites

well its looks like you the php script is not even in the html trying moveing into the <html> tag and see what happens.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.