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



如何使用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变量

尝试使用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);
}`

相关内容

  • 没有找到相关文章

最新更新