我需要模型查询的帮助,我想找到带有变量的字段,该字段是我输入到控制器中的,而现在的问题是该字段无法读取我的变量,因此这是代码
控制器
public function tampil_soal(){
$kode_soal = $this->input->post('kode_soal');
$where = array('kode_soal' => $kode_soal);
$data['tampilan']= $this->m_model->tampil_soal($kode_soal)->result();
$this->load->view('soal_tampil',$data);
}
模型
public function tampil_soal($where){
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
}
查看
<form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
<input class="input" name="kode_ujian" placeholder="Kode ujian"/>
<input class="button" type="submit" name="submit" value="Selesai"/>
</form>
答案 0 :(得分:5)
只需尝试:
//controller
public function tampil_soal(){
$kode_soal = $this->input->post('kode_ujian');
$data['tampilan']= $this->m_model->tampil_soal($kode_soal);
$this->load->view('soal_tampil',$data);
}
// model
public function tampil_soal($where){
$this->db->where('kode_soal',$where);
return $this->db->get('soal')->result();
// use the return $this->db->get('soal')->row();
// if your query return one record
}
答案 1 :(得分:0)
我认为您必须在查询中使用result()函数
Module3
答案 2 :(得分:0)
尝试以下查询: //控制器
public function tampil_soal(){
$data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
$this->load->view('soal_tampil',$data);
}
//型号
public function tampil_soal($where){
return $this->db->where('kode_soal',$where)->get('soal')->result();
}
答案 3 :(得分:0)
查看
<form action="<?php echo base_url()?>siswa/tampil_soal" method="post" class="form">
<input class="input" name="kode_ujian" placeholder="Kode ujian"/>
<input class="button" type="submit" name="submit" value="Selesai"/>
</form>
控制器
您使用了错误的帖子名称“ $ this-> input-> post('kode_soal')”,将其更改为$ this-> input-> post('kode_ujian') 然后
public function tampil_soal(){
$kode_soal = $this->input->post('kode_ujian');
$where = array('kode_soal' => $kode_soal);
$data['tampilan']= $this->m_model->tampil_soal($kode_soal);
$this->load->view('test',$data);
}
模型
public function tampil_soal($where){
$qry = $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
if($qry->num_rows()>0){
return $qry->result();
}else{
return array();
}
}
答案 4 :(得分:0)
模型
if ([[url absoluteString] hasPrefix:kCDVAssetsLibraryPrefixes]) {
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset* asset) {
if (asset) {
ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
NSString* MIMEType = (__bridge_transfer NSString*)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)[assetRepresentation UTI], kUTTagClassMIMEType);
Byte* buffer = (Byte*)malloc((unsigned long)[assetRepresentation size]);
NSUInteger bufferSize = [assetRepresentation getBytes:buffer fromOffset:0.0 length:(NSUInteger)[assetRepresentation size] error:nil];
NSData* data = [NSData dataWithBytesNoCopy:buffer length:bufferSize freeWhenDone:YES];
[self sendResponseWithResponseCode:200 data:data mimeType:MIMEType];
}
答案 5 :(得分:0)
更改此
public function tampil_soal($where){
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
}
对此
public function tampil_soal($kode_soal){
return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");
}
希望这会有所帮助