Codeigniter - mysql query with variable
up vote
0
down vote
favorite
I need help for the query in my model, I want to find the field with variable that i'm input to the controller and as for right now the problem is that the field won't read my variable so here is the code
Controller
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);
Model
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
View
<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>
php mysql codeigniter
add a comment |
up vote
0
down vote
favorite
I need help for the query in my model, I want to find the field with variable that i'm input to the controller and as for right now the problem is that the field won't read my variable so here is the code
Controller
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);
Model
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
View
<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>
php mysql codeigniter
You are passing$where
as an array, while you are not using the key's value for using it as a column inWhere
condition
– Madhur Bhaiya
Nov 12 at 6:27
Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
– Madhur Bhaiya
Nov 12 at 6:27
Have you check $kode_soal get value in controller?
– Sachin
Nov 12 at 6:33
@Sachin yes i'm already make the view input of the$kode_soal
and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
– Happy Dog
Nov 12 at 6:43
can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
– Sachin
Nov 12 at 7:50
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need help for the query in my model, I want to find the field with variable that i'm input to the controller and as for right now the problem is that the field won't read my variable so here is the code
Controller
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);
Model
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
View
<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>
php mysql codeigniter
I need help for the query in my model, I want to find the field with variable that i'm input to the controller and as for right now the problem is that the field won't read my variable so here is the code
Controller
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);
Model
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
View
<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>
php mysql codeigniter
php mysql codeigniter
edited Nov 12 at 7:41
asked Nov 12 at 6:24
Happy Dog
185
185
You are passing$where
as an array, while you are not using the key's value for using it as a column inWhere
condition
– Madhur Bhaiya
Nov 12 at 6:27
Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
– Madhur Bhaiya
Nov 12 at 6:27
Have you check $kode_soal get value in controller?
– Sachin
Nov 12 at 6:33
@Sachin yes i'm already make the view input of the$kode_soal
and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
– Happy Dog
Nov 12 at 6:43
can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
– Sachin
Nov 12 at 7:50
add a comment |
You are passing$where
as an array, while you are not using the key's value for using it as a column inWhere
condition
– Madhur Bhaiya
Nov 12 at 6:27
Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
– Madhur Bhaiya
Nov 12 at 6:27
Have you check $kode_soal get value in controller?
– Sachin
Nov 12 at 6:33
@Sachin yes i'm already make the view input of the$kode_soal
and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?
– Happy Dog
Nov 12 at 6:43
can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
– Sachin
Nov 12 at 7:50
You are passing
$where
as an array, while you are not using the key's value for using it as a column in Where
condition– Madhur Bhaiya
Nov 12 at 6:27
You are passing
$where
as an array, while you are not using the key's value for using it as a column in Where
condition– Madhur Bhaiya
Nov 12 at 6:27
Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
– Madhur Bhaiya
Nov 12 at 6:27
Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
– Madhur Bhaiya
Nov 12 at 6:27
Have you check $kode_soal get value in controller?
– Sachin
Nov 12 at 6:33
Have you check $kode_soal get value in controller?
– Sachin
Nov 12 at 6:33
@Sachin yes i'm already make the view input of the
$kode_soal
and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?– Happy Dog
Nov 12 at 6:43
@Sachin yes i'm already make the view input of the
$kode_soal
and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?– Happy Dog
Nov 12 at 6:43
can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
– Sachin
Nov 12 at 7:50
can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
– Sachin
Nov 12 at 7:50
add a comment |
6 Answers
6
active
oldest
votes
up vote
0
down vote
accepted
View
<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>
Controller
you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
then
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);
Model
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();
okay this works thank you very much
– Happy Dog
Nov 12 at 10:12
add a comment |
up vote
4
down vote
just try this:
//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
i'm sorry i don't quite understand what you are saying
– Happy Dog
Nov 12 at 7:43
okay, i will edit the answer as soon as possible
– Khalifa Nikzad
Nov 12 at 7:47
you used the wrong input name in your controller and I made it correct in code above use the above code it will work
– Khalifa Nikzad
Nov 12 at 8:06
oh, i see thank you but i already found the answer
– Happy Dog
Nov 12 at 10:13
add a comment |
up vote
0
down vote
I think you have to use result() function with query
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();
isn't the->result()
is for the controller? PS:I have tried it still not working, and it saysCall to a member function result() on a non-object
– Happy Dog
Nov 12 at 6:44
add a comment |
up vote
0
down vote
try this query:
//controller
public function tampil_soal()
$data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
$this->load->view('soal_tampil',$data);
//model
public function tampil_soal($where)
return $this->db->where('kode_soal',$where)->get('soal')->result();
You didn't add the$where
on the controller
– Happy Dog
Nov 12 at 6:48
or is there another way get the$where
from the model?
– Happy Dog
Nov 12 at 6:52
is kode_soal field exists in your datatable?
– PHP Geek
Nov 12 at 6:54
yes it exists there
– Happy Dog
Nov 12 at 7:07
add a comment |
up vote
0
down vote
Model
public function tampil_soal($where)
$condition = $where;
// Your Condition...
$this->db->where($condition);
// Order By ...
$this->db->order_by('RAND()');
// Return Data from Table ...
return $this->db->get('soal');
add a comment |
up vote
0
down vote
change this
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
to this
public function tampil_soal($kode_soal)
return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");
hope it'll helps
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256869%2fcodeigniter-mysql-query-with-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
View
<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>
Controller
you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
then
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);
Model
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();
okay this works thank you very much
– Happy Dog
Nov 12 at 10:12
add a comment |
up vote
0
down vote
accepted
View
<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>
Controller
you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
then
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);
Model
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();
okay this works thank you very much
– Happy Dog
Nov 12 at 10:12
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
View
<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>
Controller
you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
then
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);
Model
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();
View
<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>
Controller
you are using wrong post name "$this->input->post('kode_soal')" change this to $this->input->post('kode_ujian')
then
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);
Model
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();
answered Nov 12 at 8:02
Faisal Mk
765
765
okay this works thank you very much
– Happy Dog
Nov 12 at 10:12
add a comment |
okay this works thank you very much
– Happy Dog
Nov 12 at 10:12
okay this works thank you very much
– Happy Dog
Nov 12 at 10:12
okay this works thank you very much
– Happy Dog
Nov 12 at 10:12
add a comment |
up vote
4
down vote
just try this:
//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
i'm sorry i don't quite understand what you are saying
– Happy Dog
Nov 12 at 7:43
okay, i will edit the answer as soon as possible
– Khalifa Nikzad
Nov 12 at 7:47
you used the wrong input name in your controller and I made it correct in code above use the above code it will work
– Khalifa Nikzad
Nov 12 at 8:06
oh, i see thank you but i already found the answer
– Happy Dog
Nov 12 at 10:13
add a comment |
up vote
4
down vote
just try this:
//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
i'm sorry i don't quite understand what you are saying
– Happy Dog
Nov 12 at 7:43
okay, i will edit the answer as soon as possible
– Khalifa Nikzad
Nov 12 at 7:47
you used the wrong input name in your controller and I made it correct in code above use the above code it will work
– Khalifa Nikzad
Nov 12 at 8:06
oh, i see thank you but i already found the answer
– Happy Dog
Nov 12 at 10:13
add a comment |
up vote
4
down vote
up vote
4
down vote
just try this:
//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
just try this:
//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
edited Nov 12 at 8:00
answered Nov 12 at 7:37
Khalifa Nikzad
68811
68811
i'm sorry i don't quite understand what you are saying
– Happy Dog
Nov 12 at 7:43
okay, i will edit the answer as soon as possible
– Khalifa Nikzad
Nov 12 at 7:47
you used the wrong input name in your controller and I made it correct in code above use the above code it will work
– Khalifa Nikzad
Nov 12 at 8:06
oh, i see thank you but i already found the answer
– Happy Dog
Nov 12 at 10:13
add a comment |
i'm sorry i don't quite understand what you are saying
– Happy Dog
Nov 12 at 7:43
okay, i will edit the answer as soon as possible
– Khalifa Nikzad
Nov 12 at 7:47
you used the wrong input name in your controller and I made it correct in code above use the above code it will work
– Khalifa Nikzad
Nov 12 at 8:06
oh, i see thank you but i already found the answer
– Happy Dog
Nov 12 at 10:13
i'm sorry i don't quite understand what you are saying
– Happy Dog
Nov 12 at 7:43
i'm sorry i don't quite understand what you are saying
– Happy Dog
Nov 12 at 7:43
okay, i will edit the answer as soon as possible
– Khalifa Nikzad
Nov 12 at 7:47
okay, i will edit the answer as soon as possible
– Khalifa Nikzad
Nov 12 at 7:47
you used the wrong input name in your controller and I made it correct in code above use the above code it will work
– Khalifa Nikzad
Nov 12 at 8:06
you used the wrong input name in your controller and I made it correct in code above use the above code it will work
– Khalifa Nikzad
Nov 12 at 8:06
oh, i see thank you but i already found the answer
– Happy Dog
Nov 12 at 10:13
oh, i see thank you but i already found the answer
– Happy Dog
Nov 12 at 10:13
add a comment |
up vote
0
down vote
I think you have to use result() function with query
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();
isn't the->result()
is for the controller? PS:I have tried it still not working, and it saysCall to a member function result() on a non-object
– Happy Dog
Nov 12 at 6:44
add a comment |
up vote
0
down vote
I think you have to use result() function with query
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();
isn't the->result()
is for the controller? PS:I have tried it still not working, and it saysCall to a member function result() on a non-object
– Happy Dog
Nov 12 at 6:44
add a comment |
up vote
0
down vote
up vote
0
down vote
I think you have to use result() function with query
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();
I think you have to use result() function with query
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()")->result();
answered Nov 12 at 6:33
Poonam Navapara
18618
18618
isn't the->result()
is for the controller? PS:I have tried it still not working, and it saysCall to a member function result() on a non-object
– Happy Dog
Nov 12 at 6:44
add a comment |
isn't the->result()
is for the controller? PS:I have tried it still not working, and it saysCall to a member function result() on a non-object
– Happy Dog
Nov 12 at 6:44
isn't the
->result()
is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
– Happy Dog
Nov 12 at 6:44
isn't the
->result()
is for the controller? PS:I have tried it still not working, and it says Call to a member function result() on a non-object
– Happy Dog
Nov 12 at 6:44
add a comment |
up vote
0
down vote
try this query:
//controller
public function tampil_soal()
$data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
$this->load->view('soal_tampil',$data);
//model
public function tampil_soal($where)
return $this->db->where('kode_soal',$where)->get('soal')->result();
You didn't add the$where
on the controller
– Happy Dog
Nov 12 at 6:48
or is there another way get the$where
from the model?
– Happy Dog
Nov 12 at 6:52
is kode_soal field exists in your datatable?
– PHP Geek
Nov 12 at 6:54
yes it exists there
– Happy Dog
Nov 12 at 7:07
add a comment |
up vote
0
down vote
try this query:
//controller
public function tampil_soal()
$data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
$this->load->view('soal_tampil',$data);
//model
public function tampil_soal($where)
return $this->db->where('kode_soal',$where)->get('soal')->result();
You didn't add the$where
on the controller
– Happy Dog
Nov 12 at 6:48
or is there another way get the$where
from the model?
– Happy Dog
Nov 12 at 6:52
is kode_soal field exists in your datatable?
– PHP Geek
Nov 12 at 6:54
yes it exists there
– Happy Dog
Nov 12 at 7:07
add a comment |
up vote
0
down vote
up vote
0
down vote
try this query:
//controller
public function tampil_soal()
$data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
$this->load->view('soal_tampil',$data);
//model
public function tampil_soal($where)
return $this->db->where('kode_soal',$where)->get('soal')->result();
try this query:
//controller
public function tampil_soal()
$data['tampilan']= $this->m_model->tampil_soal($this->input->post('kode_soal');
$this->load->view('soal_tampil',$data);
//model
public function tampil_soal($where)
return $this->db->where('kode_soal',$where)->get('soal')->result();
answered Nov 12 at 6:44
PHP Geek
1,1691717
1,1691717
You didn't add the$where
on the controller
– Happy Dog
Nov 12 at 6:48
or is there another way get the$where
from the model?
– Happy Dog
Nov 12 at 6:52
is kode_soal field exists in your datatable?
– PHP Geek
Nov 12 at 6:54
yes it exists there
– Happy Dog
Nov 12 at 7:07
add a comment |
You didn't add the$where
on the controller
– Happy Dog
Nov 12 at 6:48
or is there another way get the$where
from the model?
– Happy Dog
Nov 12 at 6:52
is kode_soal field exists in your datatable?
– PHP Geek
Nov 12 at 6:54
yes it exists there
– Happy Dog
Nov 12 at 7:07
You didn't add the
$where
on the controller– Happy Dog
Nov 12 at 6:48
You didn't add the
$where
on the controller– Happy Dog
Nov 12 at 6:48
or is there another way get the
$where
from the model?– Happy Dog
Nov 12 at 6:52
or is there another way get the
$where
from the model?– Happy Dog
Nov 12 at 6:52
is kode_soal field exists in your datatable?
– PHP Geek
Nov 12 at 6:54
is kode_soal field exists in your datatable?
– PHP Geek
Nov 12 at 6:54
yes it exists there
– Happy Dog
Nov 12 at 7:07
yes it exists there
– Happy Dog
Nov 12 at 7:07
add a comment |
up vote
0
down vote
Model
public function tampil_soal($where)
$condition = $where;
// Your Condition...
$this->db->where($condition);
// Order By ...
$this->db->order_by('RAND()');
// Return Data from Table ...
return $this->db->get('soal');
add a comment |
up vote
0
down vote
Model
public function tampil_soal($where)
$condition = $where;
// Your Condition...
$this->db->where($condition);
// Order By ...
$this->db->order_by('RAND()');
// Return Data from Table ...
return $this->db->get('soal');
add a comment |
up vote
0
down vote
up vote
0
down vote
Model
public function tampil_soal($where)
$condition = $where;
// Your Condition...
$this->db->where($condition);
// Order By ...
$this->db->order_by('RAND()');
// Return Data from Table ...
return $this->db->get('soal');
Model
public function tampil_soal($where)
$condition = $where;
// Your Condition...
$this->db->where($condition);
// Order By ...
$this->db->order_by('RAND()');
// Return Data from Table ...
return $this->db->get('soal');
answered Nov 12 at 8:08
Darryl Ceguerra
885
885
add a comment |
add a comment |
up vote
0
down vote
change this
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
to this
public function tampil_soal($kode_soal)
return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");
hope it'll helps
add a comment |
up vote
0
down vote
change this
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
to this
public function tampil_soal($kode_soal)
return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");
hope it'll helps
add a comment |
up vote
0
down vote
up vote
0
down vote
change this
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
to this
public function tampil_soal($kode_soal)
return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");
hope it'll helps
change this
public function tampil_soal($where)
return $this->db->query("select * from soal where kode_soal='$where' ORDER BY RAND()");
to this
public function tampil_soal($kode_soal)
return $this->db->query("select * from soal where kode_soal='$kode_soal' ORDER BY RAND()");
hope it'll helps
answered Nov 12 at 8:39
Rizki Masjahri
214
214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53256869%2fcodeigniter-mysql-query-with-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You are passing
$where
as an array, while you are not using the key's value for using it as a column inWhere
condition– Madhur Bhaiya
Nov 12 at 6:27
Your code is open to SQL injection related attacks. Please learn to use Prepared Statements
– Madhur Bhaiya
Nov 12 at 6:27
Have you check $kode_soal get value in controller?
– Sachin
Nov 12 at 6:33
@Sachin yes i'm already make the view input of the
$kode_soal
and make sure that it gets the value to the controller but the problem is probably in the model? @MadhurBhaiya what do you mean that is open to SQL injection? is like get easily hacked or something?– Happy Dog
Nov 12 at 6:43
can you try echo $this->db->last_query(); so we can find your query is correct or something wrong with query?
– Sachin
Nov 12 at 7:50