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

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    I am building a variable $condition using loops and concatenations...
    then I would like to check whether $condition is true
    if I use:
    if($condition){....}

    it will always return true because it checks for the existence of $condition.
    How can I check whether $condition is true?

    (I tried if(echo"$condition"){...} but of course I got a parse error)
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    City, State, Country
    Posts
    12
    Rep Power
    0
    theirs 2 things u might be talking about here...

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?php
    if ($condition == "true") {
    ok, its true...now what?
    } else {
    ok, its false...now what?
    }
    ?>
    [/code]

    or...

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?php
    if (isset($condition)) {
    ok the variable has a value...now what?
    } else {
    ok the variable dont have a value...now what?
    }
    ?>
    [/code]

    Depending on what u mean, one of those should work.

    Number one says, if the value of $condition is, "true", then display/do this, else do this.

    Number two says, if the variable $condition exists, then display/do this, else do this.

    Hope that helps!!

    ^N|R

    ------------------
    NobodysReal@hotmail.com
    Aim: PRM Magic
    ICQ: 77968493
  4. #3
  5. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    you probably don't want to use quotes around "true" if $condition is a boolean variable
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    thanks a lot for your help, but i actually tried all of this (and tried again after your postings), and i still don't get it work, so here is my code:
    ------------------------------------------------------------------------------------------------------
    for ($b=0;$b<$countdegree;$b++){
    $condition="($getdegree[$b]==";

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

    echo "$conditionnn";
    //what I get here is: ( Ph==BSc) &#0124; &#0124; ( Ph==DDS) &#0124; &#0124; ( Ph==MD) &#0124; &#0124; ( Ph==MSc) &#0124; &#0124; ( Ph==MLT) &#0124; &#0124;
    //( Ph==PharmaD) &#0124; &#0124; ( Ph==PhD)
    //so this condition is false, right?

    if (($condition)==true){
    echo "condition true and degree is '$getdegree[$b]'";
    }
    else{
    echo "condition false and degree is '$getdegree[$b]'";
    $other_degree.="$getdegree[$b]";
    }
    }
    // however after this loop i get:condition true and degree is ' Ph'
    //so the loop does not work the way i want
    //(i tried $condition==0 or $condition== 1, same problem)

    //so I inserted this other control, where I literally cut and pasted the valur of $condition
    //that was echoed on my screen from above

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

    //and i get test OK , so there it works!!!!!

    for sure i am missing something, but I'm stuck for 2 days without figuring out what's wrong...any idea?
    Thanks!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Canada
    Posts
    35
    Rep Power
    15
    ignore my last message, i found another way to program it...
    thanks anyways!

Similar Threads

  1. dynamically created check boxes
    By wduffee in forum PHP Development
    Replies: 3
    Last Post: February 3rd, 2004, 02:10 PM
  2. To check what's in a check box?
    By coverman in forum PHP Development
    Replies: 6
    Last Post: January 19th, 2004, 10:17 PM
  3. Do compilers optimize some / into *?
    By Jason Doucette in forum C Programming
    Replies: 46
    Last Post: December 25th, 2003, 09:47 PM
  4. called too early to check prototype at mediawrap.cgi
    By jenniefer in forum Perl Programming
    Replies: 4
    Last Post: December 20th, 2003, 09:37 AM
  5. parse order question
    By wannabe in forum PHP Development
    Replies: 5
    Last Post: December 13th, 2003, 10:06 PM

IMN logo majestic logo threadwatch logo seochat tools logo