我无法从$_GET方法在编码器中显示数据库中的数据


i am unable to display data from database from $_GET method in codeigniter

<?php  if(isset($_GET['edit'])){?>
<section class="content">
<?php  
    $id=$_GET['edit'];
    $this->load->model('databasemodel');
    $data1['hello_1']=$this->databasemodel->get_data_where($id);
    foreach ($hello_1 as $test) {
    $test->title;
    }
$this->load->view('admin/headingsform'); ?>
</section>
<?php  } ?>

和我得到错误消息:未定义变量:hello_1

你从来没有给$hello_1任何值在你的代码。

通过调用codeigniter get()函数获得您的值:

$values = $this->input->get();来净化你的输入。

在检索到$data1['hello_1']的值后,您需要像这样使用它们,因此您的循环将是:foreach ($data1['hello_1'] as $test)

意味着,你的完整代码看起来像这样:

<?php  
     $get_values = $this->input->get();
     if(isset($get_values['edit'])){
?>
<section class="content">
<?php  
    $this->load->model('databasemodel');
    $data1['hello_1']=$this->databasemodel->get_data_where($get_values['edit']);
    foreach ($data1['hello_1'] as $test) { //this is the important bit
        $test->title;
    }
    $this->load->view('admin/headingsform'); ?>
</section>
<?php  } ?>