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++;}
    
    ?>

2 Answers 2

0

better add a status filter for collection

public function getCollection()
    {
        $collection = $this->collectionFactory->create()->getCollection()
        ->addFieldToFilter('status', 1);
        
        return $collection;
    }
3
  • Thank you it is working I applied addtofilter inside the loop and it is working
    – kks
    Commented Jun 24, 2021 at 7:30
  • Could you please help for how to send this form data in the owner's email?
    – kks
    Commented Jun 24, 2021 at 7:36
  • store.magenest.com/blog/how-to-send-email-in-magento-2 follow this tutorial
    – Devidas
    Commented Jun 24, 2021 at 7:38
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 and acknowledge you have read our privacy policy.

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