i struggling with forloop in MVC. i want to pass data from input text where in data is equivalent to 1,2,3,4,5,6,7...... -that is from database.
i pass it to controller and get the data using $_POST method with name text1. here is my controller code
{
$template = $this->loadView('view_display');
if(isset($_POST['check'])):
$text1= $_POST['text1'];
$text1= explode(',', $text1);
foreach($text1 as $text1):
$rem = $this->Faculty_model->testFunction($this->security_plugin->cleanInput($text1));
$template->set(['stud' => $rem, 'username' => $this->session_helper->get('username'), 'security'=> $this->security_plugin, 'url' => $this->url_helper]);
endforeach;
endif;
$this->security_plugin->CSRFToken();
$template->render();
here is my model
{
$sql="select * from table where id=:text1";
$bind = array(
':text1' => $text1
);
$data = $this->db->fetchAll($sql, $bind);
return $data;
}
and this is my view
<?php if(!empty($stud)): ?>
<?php foreach($stud as $stud): ?>
<?php echo $security->SanitizeString($stud->ID); ?>
<?php echo $security->SanitizeString($stud->NAME); ?>
<?php echo $security->SanitizeString($stud->AGE); ?>
The problem is it will only display the last number from text1 textbox. i cant figure it out.
anyhelp is appreciated :)