Thread: If statement

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

    Join Date
    Mar 2000
    Posts
    2
    Rep Power
    0
    Html For Race Selection:

    <table width="100%" border="6" cellspacing="5" cellpadding="3" align="center" style="border-color: Black; font-size: small; font-family: Verdana;">
    <tr bgcolor="#FFCCFF">
    <td rowspan="1" style="font-family: Americana XBd BT; font-size: small;">
    N.American <input type="checkbox" name="race1" value="N.American"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    W.European <input type="checkbox" name="race2" value="W.European">
    <td style="font-size: small; font-family: Americana XBd BT;">
    Far Eastern <input type="checkbox" name="race3" value="Far Eastern"></td>
    </tr>
    <tr bgcolor="#FFCCFF">
    <td rowspan="1" style="font-family: Americana XBd BT; font-size: small;">
    Australian <input type="checkbox" name="race4" value="Australian"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    New Zealand <input type="checkbox" name="race5" value="New Zealand"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    Mediterranean <input type="checkbox" name="race6" value="Mediterranean"></td>
    </tr>
    <tr bgcolor="#FFCCFF">
    <td rowspan="1" style="font-family: Americana XBd BT; font-size: small;">
    Middle Eastern <input type="checkbox" name="race7" value="Middle Eastern"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    S.Asian <input type="checkbox" name="race8" value="S.Asian"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    E.European <input type="checkbox" name="race9" value="E.European"></td>
    </tr>
    <tr bgcolor="#FFCCFF">
    <td rowspan="1" style="font-family: Americana XBd BT; font-size: small;">
    Latin American <input type="checkbox" name="race10" value="Latin American"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    Central Asian <input type="checkbox" name="race11" value="Central Asian"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    African <input type="checkbox" name="race12" value="African"></td>
    </tr>
    <tr bgcolor="#FFCCFF">
    <td rowspan="1" style="font-family: Americana XBd BT; font-size: small;">
    Afro Caribbean <input type="checkbox" name="race13" value="Afro Caribbean"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    S.African <input type="checkbox" name="race14" value="S.African"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    All Races <input type="checkbox" name="race1 race2 race3 race4 race5 race6 race7 race8 race9 race10 race11 race12 race13 race14 race15 race16 race17 " value="N.American W.European Far Eastern Australian New Zealand Mediterranean Middle Eastern S.Asian E.European Latin American Central Asian African Afro Caribbean S.African Caucasian Mixed Race Native American" checked></td>
    </tr>

    <tr bgcolor="#FFCCFF">
    <td rowspan="1" style="font-family: Americana XBd BT; font-size: small;">
    Caucasian <input type="checkbox" name="race15" value="Caucasian"></td>
    <td style="font-size: small; font-family: Americana XBd BT;">
    Mixed Race <input type="checkbox" name="race16" value="Mixed Race">
    <td style="font-size: small; font-family: Americana XBd BT;">
    Native American <input type="checkbox" name="race17" value="Native American"></td>
    </tr>
    </table>

    Php For Race:

    $race = "";
    // test for each race checked
    if($race1)
    {
    $race .= " OR race = '".$race1."'";
    }
    if($race2)
    {
    $race .= " OR race = '".$race2."'";
    }
    if($race3)
    {
    $race .= " OR race = '".$race3."'";
    }
    if($race4)
    {
    $race .= " OR race = '".$race4."'";
    }
    if($race5)
    {
    $race .= " OR race = '".$race5."'";
    }
    if($race6)
    {
    $race .= " OR race = '".$race6."'";
    }
    if($race7)
    {
    $race .= " OR race = '".$race7."'";
    }
    if($race8)
    {
    $race .= " OR race = '".$race8."'";
    }
    if($race9)
    {
    $race .= " OR race = '".$race9."'";
    }
    if($race10)
    {
    $race .= " OR race = '".$race10."'";
    }
    if($race11)
    {
    $race .= " OR race = '".$race11."'";
    }
    if($race12)
    {
    $race .= " OR race = '".$race12."'";
    }
    if($race13)
    {
    $race .= " OR race = '".$race13."'";
    }
    if($race14)
    {
    $race .= " OR race = '".$race14."'";
    }
    if($race15)
    {
    $race .= " OR race = '".$race15."'";
    }
    if($race16)
    {
    $race .= " OR race = '".$race16."'";
    }
    if($race17)
    {
    $race .= " OR race = '".$race17."'";
    }

    Mysql Query:

    $result = mysql_query("SELECT first_name, country_residence, thum_name, race, description, (to_days(now())-to_days(dob))/365 as Age from Test where country_residence like '$country_residence' AND (to_days(now())-to_days(dob))/365 >='$min_age' AND (to_days(now())-to_days(dob))/365 <='$max_age' AND height >='$min_height' AND height <='$max_height' AND weight >='$min_weight' AND weight <='$max_weight' AND current_date - period <= '$past_ads' AND marital_status like '$marital_status' $race ", $db);

    The values for Race are printed to screen.
    There are 2 Races entered in Mysql.
    E.european and Far eastern.

    If E.european is selected, both E.european and Far eastern are printed.
    If Far eastern is selected, still both are printed.
    If a particular Race, e.g. W.european is selected,which is not even in Mysql,E.european and Far eastern are still printed.

    Where can the possible correction be made to make script work properly.

    Thanks

  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    can you explain clearly(briefly) what you are intend to do???.


  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    2
    Rep Power
    0
    The race variable has many possible values.
    e.g. far eastern, e.european, mixed race, etc.etc..

    in Mysql are a 2 races. far eastern and e.european. I want to fill MYsql with many more.

    Selections from Mysql have a number of different search criteria.

    One of them is race.

    So if someone wanted to search for e.european only the results should reflect this. It should not output all other races.If someone wants to search all races, then all should be output.

    You make the choices from html form.

Similar Threads

  1. Requesting help on READTEXT statement
    By hdokes in forum MS SQL Development
    Replies: 1
    Last Post: March 19th, 2004, 09:53 AM
  2. Question about the WHERE statement
    By layz d in forum MS SQL Development
    Replies: 5
    Last Post: January 28th, 2004, 12:58 PM
  3. how can i put an IF statement inside a WHILE statement?
    By Jarrett Green in forum Perl Programming
    Replies: 4
    Last Post: December 22nd, 2003, 11:05 PM
  4. Update database/count statement
    By Signuml99 in forum Database Management
    Replies: 2
    Last Post: November 26th, 2003, 02:07 PM
  5. Figuring out parts of a mySQL statement
    By ChibiGuy in forum PHP Development
    Replies: 2
    Last Post: August 18th, 2003, 11:38 PM

IMN logo majestic logo threadwatch logo seochat tools logo