Jump to content

Recommended Posts

Hello,

 

I would like to build a php search engine against a mysql database. I am looking for a tutorial but haven't been able to find any good ones. Any ideas of where I can find one? I need one where I can search with several words and if it has the stemmer.class.inc and so on would be great also.

 

thanks, df

Link to comment
https://forums.phpfreaks.com/topic/211105-building-a-search-engine/
Share on other sites

Hello,

 

I tried this

$search=$_GET['search'];
$query="SELECT COUNT(*) as num FROM videos WHERE $search MATCH (title,titletext) AGAINST ('db' WITH QUERY EXPANSION)";

 

but get this error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 198

 

any ideas? Thanks

Ok, so you want a search query ehh?

 

I'd recomend using LIKE.

for example:

 

// $_POST is from a form "<input type="text" name="search_text"></input>" but I'm sure you know this already

$postSearch = $_POST[search_text];
$search = mysql_query("SELECT * FROM <table here> WHERE <row here> LIKE '$postSearch%' ");

//displaying the search result
while ($row = mysql_fetch_array($search) {
echo $row[<insert row here>] . '<br />';
echo $row[<insert row here>] . '<br />';
echo $row[<insert row here>] . '<br />';
}

 

First time replying to anything in any forum, I hope I made it clear enough.

if not , I'll paste a piece of my code for my search query here as an example.

if ($searchBy == "sDay") {
$search = mysql_query("SELECT * FROM syn_test WHERE Date LIKE '$postSearch%'");
while($row = mysql_fetch_array($search)) {
	echo "<tr><td>" . $row['synID'] . "</td>" . 
	         "<td>" . $row['Username'] . "</td>" . 
			 "<td>" . $row['Password'] . "</td>" . 
	         "<td>" . $row['Date'] . "</td>". 
	         "<td>" . $row['Time'] . "</td>". 
	     "</tr>";
	}
	}	

 

Hope that helps!

P.S ignore the if statement "if ($searchBY == "sDay")" that may confuse you.

 

Do a mysql_error and post the error

 

Hello,

 

I tried this

$search=$_GET['search'];
$query="SELECT COUNT(*) as num FROM videos WHERE $search MATCH (title,titletext) AGAINST ('db' WITH QUERY EXPANSION)";

 

but get this error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 198

 

any ideas? Thanks

Thanks, this is what the code looks like:

/* PAGINATION FOR *SEARCH

		*/
		$search=$_GET['search'];
		$query="SELECT COUNT(*) as num FROM videos WHERE $search MATCH (videos.title,videos.titletext) AGAINST ('db' WITH QUERY EXPANSION)";
		$total_pages = mysql_fetch_array(mysql_query($query));
		$total_pages = $total_pages[num];

		/* Setup vars for query. */
		$targetpage = "index.php"; 	//your file name  (the name of this file)
		$limit = 2; 								//how many items to show per page
		$page = $_GET['page'];
		if($page) 
			$start = ($page - 1) * $limit; 			//first item to display on this page
		else
			$start = 0;								//if no page var is given, set start to 0

		/* Get data. */


		//SQL FOR *SEARCH
		$query="SELECT * FROM videos, categories.cat WHERE $search MATCH (videos.title,videos.titletext) AGAINST ('db' WITH QUERY EXPANSION) ORDER BY
		(videos.up-videos.down) DESC
		LIMIT $start, $limit";			
		$result = mysql_query($sql);	
		echo mysql_error();

 

 

And it gives me the following error:


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/index.php on line 198
Query was empty

 

Where line 198 is the following:

$total_pages = mysql_fetch_array(mysql_query($query));

 

//SQL FOR *SEARCH
.......
$result = mysql_query($sql);

change the above to

 

$result = mysql_query($query);

 

should work

 

the problem is

u dont have a varuable $sql any where in the script u provided

 

and the query u have for search has been assigned to a varuable $query

Thanks. Now I get this error?

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 
'MATCH (videos.title,videos.titletext) AGAINST ('db' WITH QUERY EXPANSION)ORDER' at line 1

 

I am using Server version: 5.1.44

 

Any ideas what can be wrong?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.