#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    At this point, I need your help because I just cannot find my errors!...

    here is part of a script to create dynamic checkboxes and text field from a SQL database:
    ------------------------------------------------------------------------------------------------
    $checkboxes_values=array(BSc, DDS, MD, MSc, MLT, PharmaD, PhD, Other);
    $checkboxes_count=count($checkboxes_values);

    for ($b=0;$b<$countdegree;$b++){
    //$countdegree is the number of items in the array $getdegree coming from SQL

    for($a=0;$a<$checkboxes_count-1;$a++){
    $condition.="($getdegree[$b]==$checkboxes_values[$a]) &#0124; &#0124; "; }
    $condition=substr($condition, 0, -4);

    echo "$conditionnn";
    //internal control to see what's going on

    if ($condition){
    echo "$getdegree[$b]";
    //second internal control
    $other_degree="test";

    }else{
    echo "$getdegree[$b]";
    $other_degree.="$getdegree[$b]";
    }
    }
    $other_degree=substr($other_degree, 0, -2);
    echo "other degree is : $other_degree";

    ---------------------------------------------------------------------------------------------------------------------
    the if($condition) does not work the right way:
    if I have $getdegree[$b]=Ph, if($condition) should return false and i should get $other_degree.="$getdegree[$b]", but I get $other_degree.="test"

    however, when i check the value of $condition and cut and paste this value under the "if" statement below, it works fine (meaning I get "test OK"):

    if(( Ph==DDS) &#0124; &#0124; ( Ph==MD) &#0124; &#0124; ( Ph==MSc) &#0124; &#0124; ( Ph==MLT) &#0124; &#0124; ( Ph==PharmaD) &#0124; &#0124; ( Ph==PhD)){
    echo "test wrong";
    }else{
    echo "test OK";}


    does anybody know where I'm wrong????
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    59
    Rep Power
    15
    On just a quick run through of your script I found this:

    for($a=0;$a<$checkboxes_count-1;$a++){
    $condition.="($getdegree[$b]==$checkboxes_values[$a]) | | "; }
    $condition=substr($condition, 0, -4);

    the line $condition.="($getdegree[$b]==$checkboxes_values[$a]) | | ";

    I think should be
    $condition.="($getdegree[$b]=$checkboxes_values[$a] | |";

    I'll look at it more when I get home from work, but try that and see what happens, also why the checkbox_count-1? If you didn't already know, the == is the checking operator, so it checks to see if this vaule is the same as that value, where as = is the assignment operator, it assigns the right value to the left variable.

    Chris
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    the == is the checking operator, so it checks to see if this value is the same as that value
    ------------------------------------------------------------------------------------------------------------------------
    i agree with you, so because I want to compare two values i will have to keep ==

    and again the weirdest thing is when I replace '$condition' by its value (coming from the echo "$conditionnn"; line, so it's not even something I'm making), like below, it works fine!:

    if(( Ph==DDS) | | ( Ph==MD) | | ( Ph==MSc) | | ( Ph==MLT) | | ( Ph==PharmaD) | | ( Ph==PhD)){
    echo "test wrong";
    }else{
    echo "test OK";}


    and the checkbox_count-1 is because the last item of the array is 'Other', but in SQL 'other' corresponds to a something people entered in a text field (so i cannot do 'Other'=='something').
    basically in the form I have checkboxes with certain values, then one checkboxe called 'Other' :<enter other degree here>
    the corresponding value is a text field where people can enter some other degree not in the list. and if in the database i have a value which does not correspond to any of the checkboxes I want to build that text field with the value in it.
    that's the purpose of my script...
    Hope i'm clear enough!!!
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    4
    Rep Power
    0
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by gac:
    if ($condition){ ...[/quote]

    The IF statement was simply evaluating whether $condition is empty or not. Therefore the first branch of the IF statement will always be executed.

    If I understand you correctly, you could try something similar to the followings:

    // debug: the following 2 lines are for testing only; comment them out after testing
    $getdegree = array(MD, X1, X2, PhD, X3);
    $countdegree = sizeof($getdegree);

    $other_degree = Array();
    $checkboxes_values=array(BSc, DDS, MD, MSc, MLT, PharmaD, PhD, Other);

    for ($b=0; $b<$countdegree; $b++)
    if ( !in_array($getdegree[$b], $checkboxes_values) && !in_array($getdegree[$b], $other_degree) )
    $other_degree[sizeof($other_degree)] = $getdegree[$b];

    // debug: the following 2 lines are for testing only; comment them out after testing
    for ($b=0; $b<sizeof($other_degree); $b++)
    print "$other_degree[$b] = $other_degree[$b]<br>";


    At the end of the code, $other_degree will contain X1, X2 and X3 which were not in the checkboxes_values.

    Hope this helps.

Similar Threads

  1. okay so this is my page, how to do a few things?
    By chrisab508 in forum HTML Programming
    Replies: 12
    Last Post: February 4th, 2004, 07:36 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. why would this "IN" statement not be working...
    By dlumley in forum MySQL Help
    Replies: 2
    Last Post: January 18th, 2004, 07:48 AM
  4. 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
  5. Update database/count statement
    By Signuml99 in forum Database Management
    Replies: 2
    Last Post: November 26th, 2003, 02:07 PM

IMN logo majestic logo threadwatch logo seochat tools logo