Jump to content

Recommended Posts

Hi all,

 

I have implemented some search code that I have sourced off the net and have adjusted to fit my needs. What I want to be able to do is search by either fname or organisation name according to the search text which it does, but to also only select the person if the profilestatus = public.

 

I tired adding this to the query but with no luck. Can anyone advise what I'm doing wrong? Below is the code:

 

$todo=$_POST['todo'];

        if(isset($todo) and $todo=="search"){

        $search_text=$_POST['search_text'];

        $value=$_POST['type'];

        $county = Berkshire;

        //echo $type;

 

 

        $search_text=ltrim($search_text);

        $search_text=rtrim($search_text);

     

 

       

        if($value <> "designer"){

           

        $query="select * from users where fname or organisationname ='$search_text' and profilestatus='public'";

        }

        else{

            $kt=split(" ",$search_text);//Breaking the string to array of words

        // Now let us generate the sql

        while(list($key,$val)=each($kt)){

        if($val<>" " and strlen($val) > 0){$q .= " fname like  '%$val%' or organisationname like '%$val%' or ";}

 

        }// end o $kt=splif while

 

        $q=substr($q,0,(strlen($q)-3));

        // this will remove the last or from the string.

        $query="select * from users where $q ";

        }

 

        }

 

 

 

       

        echo "<br><br>";

        $nt=mysql_query($query);

       

        //echo mysql_error();

 

        ?>

 

Thanks in advance!!

Link to comment
https://forums.phpfreaks.com/topic/200157-query-question-for-search-function/
Share on other sites

Hi Ken2k7

 

I just tried breaking it up and the query still produces people that i search for but it does not take into account the condtion I have put in place for profilestatus='public'

 

This is what the code looks like now:

 

$todo=$_POST['todo'];
        if(isset($todo) and $todo=="search"){
        $search_text=$_POST['search_text'];
        $value=$_POST['type'];
        $county = Berkshire;
        //echo $type;


        $search_text=ltrim($search_text);
        $search_text=rtrim($search_text);
       

        
        if($value <> "designer"){
            
        $query="select * from users where profilestatus='public' and fname ='$search_text' or organisationname ='$search_text'";
        }
        else{
            $kt=split(" ",$search_text);//Breaking the string to array of words
        // Now let us generate the sql
        while(list($key,$val)=each($kt)){
        if($val<>" " and strlen($val) > 0){$q .= " fname like  '%$val%' or organisationname like '%$val%' or ";}

        }// end o $kt=splif while

        $q=substr($q,0,(strlen($q)-3));
        // this will remove the last or from the string.
        $query="select * from users where $q ";
        }

        }



        
        echo "<br><br>";
        $nt=mysql_query($query);
        
        //echo mysql_error();

        ?>

 

Any Ideas??

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.