Jump to content

[php] search class problem


JonnySnip3r

Recommended Posts

Hey guys im just starting to use Prepared Statements in php and i am trying to build a search but i have come across a problem. Hope someone can help or point me to more information on how to resolves this.

 

Ok here is the code below::

 

public function search($string)
{
	if(strlen($string) > 40)
	{
		return "Woow too many words, please shorten your search.";
	}
	if(empty($string))
	{
		return "I'm a search, you type things in and I find. Please enter something and try again!";
	}
	if(strlen($string) <= 3)
	{
		return "Come on dude, you expect me to find summin with that? Type some more tags in!";
	}

	$x=0;
	// Teh string could be multiple searches so explode::
	$string = explode(" ", $string);

	foreach($string as $search)
	{
		$x++;
		if($x == 1)
		{
			@$sql .= "(blog_tags LIKE '%$search%')";
		}
		else
		{
			@$sql .= " OR (blog_tags LIKE '%$search%')";
		}
	}

	$sql = "SELECT blog_tags FROM subarc_blog WHERE $sql LIMIT 40";

	// TODO:: Count how many search results found::
	$stmt = $this->conn->prepare($sql);
	$stmt->execute();
	$stmt->bind_result($search);

 

Ok by using the bind_result() i need to know how many result are being returned to add them to a variable is this correct ? if so how can i tell how many results have been returned ?

 

hope this makes sense :D

 

Link to comment
https://forums.phpfreaks.com/topic/217661-php-search-class-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.