首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP显示器

PHP显示器
EN

Stack Overflow用户
提问于 2020-04-10 23:57:30
回答 1查看 105关注 0票数 0

我在MVC中与forloop做斗争。我想从输入文本中传递数据,其中的数据相当于1,2,3,4,5,6,7.-that来自数据库。

我将其传递给控制器,并使用名称为$_POST的text1方法获取数据。这是我的控制器代码

代码语言:javascript
复制
    {
        $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();

这是我的模型

代码语言:javascript
复制
    {
        $sql="select * from table where id=:text1";
        $bind = array(
            ':text1' => $text1
        );
        $data = $this->db->fetchAll($sql, $bind);
        return $data;
    }

这就是我的观点

代码语言:javascript
复制
<?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); ?>

问题是它将只显示text1文本框中的最后一个数字。我搞不懂。

任何帮助都很感谢:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-11 00:09:53

1.您需要在$rem之前将foreach()定义为数组,然后进行值的赋值。

2.将$template->set()代码放在foreach()之外

代码语言:javascript
复制
$template = $this->loadView('view_display');
if(isset($_POST['check'])):
    $text1= $_POST['text1'];
    $text1= explode(',', $text1);
    $rem = [];
    foreach($text1 as $text1):
    $rem[] = $this->Faculty_model->testFunction($this->security_plugin->cleanInput($text1));
    endforeach;
    $template->set(['stud' => $rem, 'username' => $this->session_helper->get('username'), 'security'=> $this->security_plugin, 'url' => $this->url_helper]);
endif;

$this->security_plugin->CSRFToken();
$template->render();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61150391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档