My controller:
public function thread($page = 'empty')
{
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
//User data variable grab
//default template load data
$data['thread'] = $this->thread_model->get_thread($page);
$data['title'] = ucfirst($page); // Capitalize the first letter
$data['replies'] = $this->thread_model->get_reply($data['thread']['thread_id']);
$this->thread_model->view_increment($data);
$this->load->view('templates/head', $data);
$this->load->view('main/wrapper-start', $data);
$this->load->view('templates/leftbar', $data);
$this->load->view('main/thread', $data);
$this->load->view('main/wrapper-end', $data);
$this->load->view('templates/footer', $data);
}
The error appears on the $data['replies'] line:
Severity: Notice
Message: Undefined index: thread_id
Filename: controllers/main.php
Line Number: 40
Here is my model code that replies refers to: $this->thread_model->get_reply
public function get_reply($thread_id)
{
$query = $this->db->query("SELECT r.reply_id FROM reply_thread rt
INNER JOIN replies r
ON rt.reply_id = r.reply_id
WHERE thread_id = ". $thread_id);
$replies = $query->result_array();
$replyarray = array();
foreach ($replies as $reply)
{
$id = $reply['reply_id'];
$query = $this->db->query("SELECT * FROM replies WHERE reply_id='$id'");
$thisRow = $query->row_array();
$replyarray[] = $thisRow;
}
return $replyarray;
}
Any ideas why this error is popping up? Other than the error, the page loads perfectly fine...all the info is in tact and available through the query.
here is my get_thread model
public function get_thread($page)
{
$slug = $page;
$query = $this->db->get_where('thread', array('slug' => $slug));
return $query->row_array();
}
using a print_r($data['thread']); I get this array:
Array ( [thread_id] => 233 [owner_id] => 8 [subject] => Repercussions of D3 addiction [body] => 1. signs of unhygienic practices 2.become irritable when forced to stop playing 3. carpal tunnel 4. loss of interest in pursuing a significant other 5. sleep deprivation 6. malnutrition There's nothing positive about this. [timestamp] => 2012-05-08 19:03:02 [replystamp] => 2012-05-09 12:38:32 [last_post_id] => 3 [slug] => 233-repercussions-of-d3-addiction [replies_num] => 2 [views] => 21 )
I think you could try this:
$threadinfo = $this->thread_model->get_thread($page);
$data['thread'] = $threadinfo;
$data['replies'] = $this->thread_model->get_reply($threadinfo->thread_id);
Related
I'm trying to get all item series from a deposit but the deposit id is on a related table. On this function i'll list all the series between two sequences requested
public function getSeries($params = [])
{
$data = collect($params);
$inicio = $data->only('serie_in');
$fim = $data->only('serie_fi');
$depOrigem = $data->only('id_origem');
$series = [];
for($i = $inicio; $i <= $fim; ++$i)
{
$item = Item::leftJoin('produtoItem', 'produtoItem.id', '=', 'item.id_produtoItem')->where('serie', $i)->where('produtoItem.id_deposito', $depOrigem)->first();
if(empty($item))
{
$status = 'I';
}
else
{
$status = $item->status;
}
$series[] = [
'serie' => $i,
'status' => $status
];
}
$result = [
'status' => true,
'data' => $series
];
return $result;
}
This is the error message, i'm thinking that must be as sintax error, but a dont realy know what? Can you help me?
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 2031 (SQL: select * from item left join produtoItem on produtoItem.id = item.id_produtoItem where serie = ? limit 1) in file /usr/share/nginx/html/controleestoque/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 671
I was calling the request on my controller without a validator, so i rewrite the getSeries method.
public function getSeries(Request $request){
$data = $request->only(['serie_in', 'serie_fi', 'id_origem']);
$result = $this->produto_service->getSeries($data);
return response()->json($result);
}
And my function work it !
i have a problem on passing data result to another data request in a controller in codeigniter is there something i'm missing ?
Controller method :
public function index()
{
//sending $data array of variables to view's or to model's
$data = array('header_title' => 'Nova Democracia - Eleições 2019 - Menu');
$data['formData'] = $this->Crud_model->getProvinciaAndLocal($this->session->id_local);
$data['locais'] = $this->Crud_model->getLocaisByIdLocal($formData["id_distrito"]);
$this->load->view("form_menu/form_menu.php", $data);
}
and my model methods :
function getProvinciaAndLocal($id_local){
$query = $this->db->query("SELECT `nome_local`, `nome_provincia`, tb_local.id_distrito
FROM `tb_user`
INNER JOIN `tb_local`
ON tb_user.id_local = tb_local.id_local
INNER JOIN `tb_distrito`
ON tb_local.id_distrito = tb_distrito.id_distrito
INNER JOIN `tb_provincia`
ON tb_distrito.id_provincia = tb_provincia.id_provincia
WHERE tb_user.id_local = '".$id_local."' ");
$row = $query->row();
$obj = array(
'nome_provincia' => $row->nome_provincia,
'nome_local' => $row->nome_local,
'id_distrito' => $row->id_distrito
);
return $obj;
}
function getLocaisByIdLocal($id_distrito){
$query = $this->db->query("SELECT tb_local.id_local, `nome_local`
FROM `tb_user`
INNER JOIN `tb_local`
ON tb_user.id_local = tb_local.id_local
INNER JOIN `tb_distrito`
ON tb_local.id_distrito = tb_distrito.id_distrito
INNER JOIN `tb_provincia`
ON tb_distrito.id_provincia = tb_provincia.id_provincia
WHERE tb_local.id_distrito = '".$id_distrito."' ");
$row = $query->row();
$obj = array(
'id_local' => $row->id_local,
'nome_local' => $row->nome_local,
);
return $obj;
}
Is there something im doing wrong? Because when i use $formData["nome_provincia"] in the view it works well..
Change your controller like this.
public function index()
{
//sending $data array of variables to view's or to model's
$data = array('header_title' => 'Nova Democracia - Eleições 2019 - Menu');
$data['formData'] = $this->Crud_model->getProvinciaAndLocal($this->session->id_local);
$data['locais'] = $this->Crud_model->getLocaisByIdLocal($data['formData']["id_distrito"]); // Notice the change here
$this->load->view("form_menu/form_menu.php", $data);
}
This is my controller:
$key['conversation_id']=1;
$update_data['is_read']=0;
$getupdate = $this->Common_model->update_msg($key,$update_data);
This is my model
function update_msg($updatekey, $updatevalue) {
$result = $this->mongo_db->db->messages->update($updatekey,array('$set'=> $updatevalue));
return $result;
}
if I try to print the response then I will get the following result
Array ( [updatedExisting] => 1 [n] => 1 [connectionId] => 10 [err] => [ok] => 1 )
$converstion_id=1;
$update_data=0;
$getupdate = $this->Common_model->update_msg($converstion_id,$update_data);
//In Model
function update_msg($converstion_id, $update_data)
{
$result = $this->mongo_db->db->messages->update(array("converstion_id"=>$converstion_id),array('$set'=>array("is_read"=>$update_data)));
return $result;
}
try this code..
$key['conversation_id']=1;
$update_data['is_read']=0;
$data_array['$set'] = $update_data;
$result = this->mongo_db->db->messages->update($key, $data_array);
return $result;
Here is the code :
foreach ($test_scores as $score) {
switch ($score['name']) {
case 'LE-TOD':
$le_tod = $score['banding'];
$le_tod_desc = $score["result_desc"];
if($score['std_score'] == 0) {
$le_tod_small = $scoring['tod']['no_pref_bottom'];
}
else {
$le_tod_small = $scoring['tod']['pref_bottom'].$score['banding'];
}
break;
This is where I get the error message :
public static function generateLSPReportFile($dataInput, $auto_download = true)
{
$file_type = $dataInput['file_type'];
$test_type_id = $dataInput['test_type_id'];
$he_she = array('male' => 'He', 'female' => 'She');
$his_her = array('male' => 'his', 'female' => 'her');
$candidate = \Candidate::where('id',$dataInput['candidate_id'])->first();
if(!$candidate)
return;
$candidate = $candidate->toArray();
$candidate_name = $candidate['first_name'].' '.$candidate['last_name'];
$order = \Order::with('client')->find($dataInput['order_id']);
if(!$order)
return;
$client = $order->client;
$order = $order->toArray();
//for test dates
$order_candidate = \OrderCandidate::candidateId($dataInput['candidate_id'])->orderId($dataInput['order_id'])->first()->toArray();
$order_tests = \OrderCandidateTest::orderCandidateId($order_candidate['id'])
->status(\Config::get('kcg.candidate_test_status_taken'))
->testId($dataInput['test_id'])
->with(array('test' => function($query){
$query->select(['id', 'name', 'description', 'abbreviation']);
}));
$tests_scores = \OrderCandidateTestScore::orderId($dataInput['order_id'])
->candidateId($dataInput['candidate_id'])
->testId($dataInput['test_id'])
->with(array('test' => function($query){
$query->select(['id', 'name', 'description', 'test_type_id']);
}));
$test_type = TestType::find($test_type_id);
$test_scores = $tests_scores->orderBy('sequence_no')->get()->toArray();
$order_tests = $order_tests->get()->toArray();
if(!$order_tests)
return;
if(!$tests_scores)
return;
It posted an error : ErrorException Undefined offset: 2. I'm really not sure what's causing this.
What am I doing wrong here? Please help me. Thank you
Typically, the Undefined offset message would be triggered by trying to access an array key which doesn't exist.
It seems that your code example might not actually be showing the part that triggered the error... In your case, I would expect the code to show something like $var[2], where the array does not actually contain an index of 2.
See this other question for a clearer representation of what that error means.
I'm trying to get the data from array in my controller php on Cakephp.
I have this function:
public function updateUserStatus() {
if(isset($this->params['url']["pcs"])) {
$uus = array( "pcs" =>$this->params['url']["pcs"] );
$trans = $this->Transaction->updateUserStatus($uus);
} else {
$trans = "failed";
}
$this->set('trans', $trans);
$this->layout = 'ajax';
}
And I want to get the data from status_id who have this response:
Array (
[0] => Array
(
[status_id] => 2
)
[1] => Array
(
[rem_time] => 66
)
)
How can I do it?
My question is how can i get the data for status_id ?
public function updateUserStatus() {
if (isset($this->params['url']["pcs"])) {
$uus = array("pcs" =>$this->params['url']["pcs"]);
$trans = $this->Transaction->updateUserStatus($uus);
} else {
$trans = "failed";
}
$currentStatus = 0;
if (is_array($trans) && isset($trans['status_id'])) {
$currentStatus = $trans['status_id'];
}
$this->set('trans', $trans);
$this->layout = 'ajax';
}
public function updateUserStatus($uus){
if(isset($uus["pcs"])) {
$sql = "SELECT status_id as status_id , rem_time as rem_time FROM phones WHERE pcs = '".$uus["pcs"]."' LIMIT 1";
$query = $this->query($sql);
return $query[0]['phones'];
} else {
return "failed";
}
}
Notice, we are returning $query[0]['phones'].
Let me know if it works.
The code could also use some refactoring.
For example, why is the function called updateUserStatus if it is only returning the result of a query? It should also always return an array, for consistency.