codeigniter 如何在ci3上获取控制器中的数据

ruarlubt  于 8个月前  发布在  其他
关注(0)|答案(1)|浏览(70)

如何使用codeigniter 3框架在控制器中获取数据
我在CI3控制器中有这样的代码:

public function ajax_list()
{
$list = $this->thesis_title->get_datatables();
$data = array();
$no = $_POST['start'];
$text1 = "Detection of student assignments based on document.";
$text2 ="test program simple levenshtein distance";
$distance=levenshtein($text1, $text2);

foreach ($list as $text_title) {
$no++;
$row = array();
$row[] = $no;
$row[] = $title_text->id_title;
$row[] = $title_text->title;
$row[] = $distance;

$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->title_thesis->count_all(),
"recordsFiltered" => $this->title_thesis->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}

我想做的是从数据库中检索标题数据,并将该值赋给$text1变量

qmb5sa22

qmb5sa221#

尝试使用foreach循环访问数据库中的标题,

public function ajax_list()
{
   $list = $this->thesis_title->get_datatables();
   
   foreach($list as $l){
      $title = $l->title //<------------(your title column at database);
   }

   $data = array();
   $no = $_POST['start'];
   $text1 = $title; //<-------inserting result of looping in the variable text1
   $text2 ="test program simple levenshtein distance";
   $distance=levenshtein($text1, $text2);

   foreach ($list as $text_title) {
   $no++;
   $row = array();
   $row[] = $no;
   $row[] = $title_text->id_title;
   $row[] = $title_text->title;
   $row[] = $distance;

   $data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->title_thesis->count_all(),
"recordsFiltered" => $this->title_thesis->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}`

相关问题