We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48586
    • 78 Posts
    rjohnson375 Reply #1, 9 years ago
    I'm working on a snippet, and based on a table value I want to display an image.

    In my database I have created a column called checkmark and it has a value of 0 or 1, to determine whether or not to display a checkmark image.

    My snippet is set to query all rows in the db:

    $query = $modx->newQuery('tampa');
    $query->sortby('listings');


    I have my output set to get a chunk to fill in the values:

    foreach($listings as $listing) {
        $fields = $listing->toArray();
        $output .= $modx->getChunk('listings_display_chunk', $fields);


    I am running into an issue trying to figure out the right way to set the logic on whether or not to show the checkbox image, basically I want something like:

    if (checkmark //not sure how to call a column name here from the db, I think this is where I am stuck
    == '1') {
    $checkfield = '<img src="check.png" />;
    } else {
    $checkfield = ' ';
    }


    Thank you in advance for any help, I'm sure I'm missing something simple here and just not seeing it.

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      I think, you want something like that:

      
      foreach ($listings as $listing) {
          $fields = $listing->toArray();
          if ($listing->get('checkmark') == '1') {
              $fields['checkfield'] = '<img src="check.png" />';
          } else {
              $fields['checkfield'] = '';
          }
          $output .= $modx->getChunk('listings_display_chunk', $fields);
      }
      


      But you could also just use migxLoopCollection like that:

      [[migxLoopCollection?
      &packageName=`yourPackage`
      &classname=`tampa`
      &sortConfig=`[{"sortby":"listings"}]`
      &tpl=`listings_display_chunk`
      ]]


      In the chunk use an outputfilter like:

      [[+checkfield:is=`1`:then=`<img src="check.png" />`:else=``]]

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 48586
        • 78 Posts
        rjohnson375 Reply #3, 9 years ago
        Thank you very much! That was the missing piece of the puzzle. I really need to get on board with MIGX, it seems to do just about everything I need.