#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Berlin,Germany
    Posts
    6
    Rep Power
    0
    Hello,

    how can I search two variables in a database?

    e.g. the result of 2 input fields.

    thanks in advance,

    Ron
  2. #2
  3. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    thane
    Posts
    50
    Rep Power
    0
    mysql_query("select * from tablename where field1=$variable1 and field2=$variable2");

    is this wht u want?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Berlin,Germany
    Posts
    6
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by ranjeet:
    mysql_query("select * from tablename where field1=$variable1 and field2=$variable2");

    is this wht u want?
    [/quote]

    yes, but what is when one variable is emty?

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Helden,Limburg,The Netherlands
    Posts
    33
    Rep Power
    15
    Hi,

    Just check with an if/else statement if one of the variables is empty and according to that info you let the program issue a different query.

    Good luck,

    ------------------
    Ramon Litjens
    Boradoli Web Design
    (www.boradoli.nl)
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    2
    Rep Power
    0
    or you can use JavaScript for field verification. - I use this a lot so that it simplifies my core php code, I don't have to have a "check_field()" handler, instead I let JavaScript (on their browser) do the work of checking fields for empty values, and/or invalid data. Inside your FORM tag, next to the method="post" or "get" do on OnSubmit="check_fields()" - where check_fields() is your javascript function that checks the text boxes. From there you can pop up alert boxes to notify the user - to say, "HEY, you left a box empty . . ."

    Sincerely,
    Jay.
  10. #6
  11. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    thane
    Posts
    50
    Rep Power
    0
    u have to use both form of checking whether the variable is empty since sometimes clients don't preffer to run javascripts on their computer.

    here u will need php checking also ...

    good luck
    ranjeet
  12. #7
  13. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Roland_Berlin,

    use isset() function in php to check empty variable.

    <?php

    if (isset($variable1) && isset($variable2)){
    //search

    }else{

    if (!isset($variable1)){
    print "Error!You have not entered first fieldn";
    }elseif((!isset($variable2){
    print "Error!You have not entered second fieldn";
    }
    exit;
    }
    ?>




    ------------------
    SR -
    shiju.dreamcenter.net

Similar Threads

  1. Frames hijacked after remote search
    By Telejoke in forum Antivirus Protection
    Replies: 2
    Last Post: September 26th, 2007, 09:32 AM
  2. Highlight search result from mysql database search
    By Gurt in forum PHP Development
    Replies: 3
    Last Post: February 17th, 2004, 03:39 AM
  3. search my products database
    By SeenGee in forum PHP Development
    Replies: 9
    Last Post: February 5th, 2004, 05:00 PM
  4. Database search highlighting problem - Stuck!
    By nro in forum PHP Development
    Replies: 5
    Last Post: January 30th, 2004, 08:44 PM
  5. searching database using php variables
    By abbynormal in forum PHP Development
    Replies: 1
    Last Post: January 24th, 2004, 07:19 PM

IMN logo majestic logo threadwatch logo seochat tools logo