Jump to content

[SOLVED] brain teaser for the smart ones


HAVOCWIZARD

Recommended Posts

guys i have a very confusing question, my search is working so far perfect, but, i do i basic search okey, no result because the search string is let say 2 words, no problem, do my advance search finds the world the use if statement and getting the pefect result, now even 3 words work, but now what happens if i have to search 5 words, how can i make it start search on the back of the string because if have

$find= explode(" ", $find);
for($loop_keywords = 0; $loop_keywords <= count($find); $loop_keywords++)
		{

			//$find[$loop_keywords] = $find[$loop_keywords];
				$find1 = $find[$loop_keywords];

the i query each word, when i find the word i go check on the if statement, how can i make this start at the end of the words

 

Link to comment
Share on other sites

when you declare your function:

 

function myfunction($var1,$var2,$var3='foobar'){
//function
}

 

And when you use you function

myfunction($somevar,$someothervar);

 

As you will notice, the third variable in the function definition was given a value. This makes the parameter optional. You can still pass a value for that function, or you can leave it as the default.

Link to comment
Share on other sites

after i ran the function it doesnt return my result why, here is what i did.


function worddisplay($wordcount,$find,$result)
{
if ($wordcount == 2)
{
	$find1 = $find[1];
	$data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'");   
	//$result = mysql_fetch_array( $data);
	while ($result = mysql_fetch_array( $data))
	{
		if ($result == "")
			{
				$find1 = $find[0]." ".$find[1];
				$data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'");   
				//$result = mysql_fetch_array( $data);
				while ($result = mysql_fetch_array( $data))
				{
					return ($result);	
				}
			}
		else 
			{
				return ($result = mysql_fetch_array($data));	
			}

	}	
}
}


worddisplay($wordcount,$find,$result);
{
   echo($result['register_companyName'];
}

 

why doesnt it give my result to echo ?

Link to comment
Share on other sites

Try:

 

<?php
function worddisplay($wordcount,$find,$result)
{
if ($wordcount == 2)
{
	$find1 = $find[1];
	$data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'");   
	//$result = mysql_fetch_array( $data);
	while ($result = mysql_fetch_array( $data))
	{
		if ($result == "")
			{
				$find1 = $find[0]." ".$find[1];
				$data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'");   
				//$result = mysql_fetch_array( $data);
				while ($result = mysql_fetch_array( $data))
				{
					return ($result);	
				}
			}
		else 
			{
				return (mysql_fetch_array($data));	
			}

	}	
}
}


$result = worddisplay($wordcount,$find,$result);
{
  echo($result['register_companyName'];
}
?>

Link to comment
Share on other sites

thanks guys for all the help, got it right when search full text then check every field, but i sitting with something else now, is the a limit on mysql query? because it doesnt search on my keywords1. here is what i have.

if ($wordcount == 4)
{
	$find1 = $find[3];
	$find1 = strtoupper($find1); 
	$find1 = strip_tags($find1); 
	$find1 = trim ($find1);

	$data = mysql_query("SELECT * FROM registrations WHERE register_companyName = '$find1' or register_contactPerson = '$find1' or register_telephoneNumber = '$find1' or register_telephoneNumber2 = '$find1' or register_faxNumber = '$find1' or register_cellphoneNumber = '$find1' or register_emailAddress = '$find1' or register_website = '$find1' or register_address1 = '$find1' or register_address2 = '$find1' or register_area = '$find1' or register_suburb = '$find1' or register_province = '$find1' or register_country = '$find1' or register_postalCode = '$find1' or register_business = '$find1' or register_description = '$find1' or register_trading = '$find1' or register_Mcat = '$find1' or register_keyword1 = '$find1' or register_keyword2 = '$find1' or register_keyword3 = '$find1' or register_keyword4 = '$find1' or register_keyword5 = '$find1' or register_keyword6 = '$find1' or register_keyword7 = '$find1' or register_keyword8 = '$find1' or register_keyword9 = '$find1' or register_keyword10 = '$find1' or register_keyword11 = '$find1' or register_keyword12 = '$find1' or register_keyword13 = '$find1' or register_keyword14 = '$find1' or register_keyword15 = '$find1' or register_keyword16 = '$find1' or register_keyword17 = '$find1' or register_keyword18 = '$find1' or register_keyword19 = '$find1' or register_keyword20 = '$find1' or register_latitude = '$find1' or register_longitude = '$find1'");   
	while ($result = mysql_fetch_array( $data));
	{

if i put in the keyword on its own it works, but if i have four words it seaches on the last word and i checked that word is there, but i goes though to the find==""; function, not good, what can be the problem

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.