• Resolved jslom

    (@jslom)


    Hello, and thank you for such a wonderful plugin!

    I have successfully used some if statements to pull information and display an image depending on the users selection, but need help with the last one.

    First, this is one of the examples of a field I am pulling..

    <?php
    $platform = xprofile_get_field_data( 'What platform do you play on the most?', $member_id ); if ( $platform == 'Playstation 3' ) echo '<img src="ps3-icon.png">'
    ?>

    Where “What platform do you play on the most?” is the name of my selection box. The one above works fine for a drop down selection box.

    I am trying to do the same if statement, but with a checkbox setup and it doesn’t seem to use the same code.

    I’ve tried a few variations of code like below, but have been unsuccessful on getting it to display.

    <?php
    xprofile_get_field_data( 'What Games Are You Frequently Playing?', $member_id ); if ( $games == (isset($_POST['Call Of Duty: Ghosts'])) && $_POST["Call Of Duty: Ghosts"] == 1 ) echo '<img src="codghosts.png">'
    ?>

    Any help would be wonderful, thanks! Also if you notice anything I am doing wrong, please let me know I am still learning!

    https://www.ads-software.com/plugins/buddypress-xprofile-custom-fields-type/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author donmik

    (@atallos)

    Hi,

    This is not in the scope of my plugin…

    Checkboxes are stored as an array. If you make a var_dump of the data like this:

    <?php $games = xprofile_get_field_data( 'What Games Are You Frequently Playing?', $member_id ); var_dump($games); ?>

    You will see something like this:

    array (size=2)
      0 => string 'Call of Duty' (length=12)
      1 => string 'Other games' (length=11)

    So, to check against an array you must do this:

    if (in_array('Call Of Duty: Ghosts', $games)) echo '<img src="codghosts.png">';

    Thread Starter jslom

    (@jslom)

    Thank you!

    I had the code last night that worked, and now I seemed to have not saved it lol

    I will try and figure it out again with the code above!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP If Statement Help’ is closed to new replies.