search by 4 input box

[b][red]This message was edited by sharingan at 2007-2-27 0:39:42[/red][/b][hr]
[b][red]This message was edited by sharingan at 2007-2-27 0:39:29[/red][/b][hr]
hai...

im again...

i have a problem regarding search script...

i have 4 input box..
user can view the data regarding the value entered in each input box..

the problem is...
the user can either insert data to 1st input box , 2nd input box , 3rd input box , 4th input box or either 1 or 2 or 3 or 4 input box according to user.

The codes:

$result = mysql_query("SELECT * FROM employee_list WHERE a LIKE '$a' AND b LIKE '$b' AND c LIKE '$c' AND d LIKE '$d'");

anything that ive miss?
:p








Comments

  • : [b][red]This message was edited by sharingan at 2007-2-27 0:39:42[/red][/b][hr]
    : [b][red]This message was edited by sharingan at 2007-2-27 0:39:29[/red][/b][hr]
    : hai...
    :
    : im again...
    :
    : i have a problem regarding search script...
    :
    : i have 4 input box..
    : user can view the data regarding the value entered in each input box..
    :
    : the problem is...
    : the user can either insert data to 1st input box , 2nd input box , 3rd input box , 4th input box or either 1 or 2 or 3 or 4 input box according to user.
    :
    : The codes:
    :
    : $result = mysql_query("SELECT * FROM employee_list WHERE a LIKE '$a' AND b LIKE '$b' AND c LIKE '$c' AND d LIKE '$d'");
    :
    : anything that ive miss?
    : :p
    :
    :
    :
    :
    :
    :
    :
    :
    :

    Hi
    the query is right however, you would have to check if the input boxes contain any data before you continue.

    You should also concatenate the where string. like so.

    start with a
    whereStr = ""
    if ($a){
    whereStr .= " and a like "$a"
    }
    if ($b){
    whereStr .= " and b like "$b"
    }
    and so on. So only the input boxes having values will be searched for.

    then at the end, if the whereStr contain any string then prepend the where clause.
    newWhereStr ="";
    if($whereStr){
    newWhereStr = "where".$whereStr
    }

    I hope this would help in some way.

    and try not to write the query string into the mysql query method directly.

    Omo
  • : : [b][red]This message was edited by sharingan at 2007-2-27 0:39:42[/red][/b][hr]
    : : [b][red]This message was edited by sharingan at 2007-2-27 0:39:29[/red][/b][hr]
    : : hai...
    : :
    : : im again...
    : :
    : : i have a problem regarding search script...
    : :
    : : i have 4 input box..
    : : user can view the data regarding the value entered in each input box..
    : :
    : : the problem is...
    : : the user can either insert data to 1st input box , 2nd input box , 3rd input box , 4th input box or either 1 or 2 or 3 or 4 input box according to user.
    : :
    : : The codes:
    : :
    : : $result = mysql_query("SELECT * FROM employee_list WHERE a LIKE '$a' AND b LIKE '$b' AND c LIKE '$c' AND d LIKE '$d'");
    : :
    : : anything that ive miss?
    : : :p
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    :
    : Hi
    : the query is right however, you would have to check if the input
    : boxes contain any data before you continue.
    :
    : You should also concatenate the where string. like so.
    :
    : start with a
    : whereStr = ""
    : if ($a){
    : whereStr .= " and a like "$a"
    : }
    : if ($b){
    : whereStr .= " and b like "$b"
    : }
    : and so on. So only the input boxes having values will be searched
    : for.
    :
    : then at the end, if the whereStr contain any string then prepend the
    : where clause.
    : newWhereStr ="";
    : if($whereStr){
    : newWhereStr = "where".$whereStr
    : }
    :
    : I hope this would help in some way.
    :
    : and try not to write the query string into the mysql query method
    : directly.
    :
    : Omo
    :
    TIP: use sentences like :...." OR `b` LIKE '%".$b."%' ....
    Use %:)
    ---------WEB---------
    Publish your website for free here:
    Real Free Open Directory - http://www.new-dmoz.org
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories