0

/I need those questions whose status is 1 but its not working/

 <?php $i=1;
    //$coll=$collection->getSelect()->where("`main_table`.`status`= 1");
    //$collection->load(true); // To dump the sql as text again and its working fine
    
     foreach ($collection->getSelect()->where("`main_table`.`status`= 1") as $item) {?>
          <div class="form-group">
            <label for="requirement">Question :</label>
            <input type="text" class="form-control" id="name" placeholder="Enter Question" name="question<?=$i?>" 
            value="<?= $item->getQuestion();?>">
            <div class="form-group">
            <label for="requirement">Answer :</label>
            <textarea class="form-control" rows="5" id="requirement" name="answer<?=$i?>">
            </textarea>
     
       <?php $i++;}
    
    ?>
0

better add a status filter for collection

public function getCollection()
    {
        $collection = $this->collectionFactory->create()->getCollection()
        ->addFieldToFilter('status', 1);
        
        return $collection;
    }
3
0

Just inject your CollectionFactory or model Factory dependency in your constructor like the following -

{
   protected $collection;

   public function __construct(
    \Vendor\Module\Model\ResuorceModel\YOUR_ReourceModelName\CollectionFactory $collection
   ){
      $this->collection = $collection;
   }

   public function getCollection()
   {
      return $this->collection->create()->addFieldToFilter('status', 1);
   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.