来自多个表的代码点火器的结果数据

时间:2018-08-27 11:00:39

标签: mysql codeigniter jointable

型号:

public function show_data_by_tid_pic($postid,$postpic) {
$condtid = "otslm.tid =" . "'" . $postid . "'";
$condpic = "pic.nama =" . "'" . $postpic . "'";
$this->db->select('otslm.*');
$this->db->select('pic.*');
$this->db->from('otslm');
$this->db->join('pic', 'pic.id = otslm.id');
$this->db->where($condtid);
$this->db->where($condpic);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result(); } else {
return false;
}
}

控制器:

public function inputslm() {
    $postid = $this->input->post('nametid');
    $postpic = $this->input->post('namepic');
    if ($postid != "" OR $postpic != "") {
    $resultid = $this->skejuler_model->show_data_by_tid_pic($postid,$postpic);
    if ($resultid != false) {
    $data['result_display'] = $resultid;
    }
    else {
    $data['result_display'] = "Not Found!";
    }
    }
    else {
    $data = array(
    'tid_error_message' => "TID tidak boleh kosong!",
    'pic_error_message' => "PIC tidak boleh kosong!"
    );
    }
    $data['show_table'] = $this->view_table();
    $this->load->view('front/dashboard', $data);
    }

查看:

if (isset($result_display)) {
            if ($result_display == 'Not Found!') {
            echo $result_display;
            } else {
                foreach ($result_display as $vid) {
                $zlokasi = $vid->lokasi;
            $znama = $vid->nama;
            $znohp = $vid->nohp;
                }
      echo $zlokasi;
      echo "<br>";
      echo $znama;
      echo "<br>";
      echo $znohp;
            }
            }

提交后:

image

我是Codeigniter的新手,他试图通过将表与2个字段“ nametid”和“ namepic”联接来生成数据。我认为代码没有错,存在列,但是它总是变成false(未找到!)。请帮忙弄清楚这一点...非常感谢...

使用HeidiSQL(找到的行:0),连接表失败,where子句。 Pic 1

使用HeidiSQL(找到的行:31),不使用where子句的Join table Success。 Pic 2

1 个答案:

答案 0 :(得分:0)

现在无需使用JOIN即可成功获取数据,将查询替换为:

[HttpPost("Delete/{id}", Name = "DeleteRoute")]
[Authorize(Roles = "SuperUser")]
public async Task<IActionResult> DeleteAsync(string id)
{
    Console.WriteLine("Deleting user: " + id);
    try {
        var user = await _userManager.FindByIdAsync(id);

        if(user == null)
            // ... 

        await _userManager.DeleteAsync(user);
        return Ok();
    } catch(Exception e) {
        return BadRequest(e.Message);
    }
}