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
Share on other sites

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.