Results 1 to 3 of 3

Thread: Where I make mistake in this if function?

  1. #1
    Join Date
    Aug 2006
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Where I make mistake in this if function?

    I have problem with simple if function. I can't get it to work although I tried everything, and I really don't know what is problem.

    PHP Code:
    <?php
    $my_field_id 
    get_option('my_field_id');
    $broj 1;

    function 
    my_field_callback() { ?>
    <input name="my_field_id" type="checkbox" value="1" 
    <?php
         
    if ($my_field_id == $broj)
         {
             print(
    'checked="checked"');
         } 
    ?>
     />
    <?php ?>
    So get_option is WordPress function and it gets value correctly. If I echo $my_field_id I get correct values, either 0 or 1. This if should check if value is one and in that case it should print that checkbox is checked and if it is 0, it should print.

    Problem is that no matter what value is, "checked" is always printed. What I'm doing wrong?

    Thanks in advance
    Last edited by blastbb; 08-09-2009 at 08:33 PM. Reason: issue resolved

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    In here, add the parts in red:

    Code:
    function my_field_callback() { 
     global $my_field_id, $broj;
    ?>
    That will make the variables available inside the function (which they currently are not).

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    blastbb (08-09-2009)

  4. #3
    Join Date
    Aug 2006
    Posts
    10
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Yeah, that was it, thank you a lot!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •