Welcome Guest, Not a member yet? Register   Sign In
Why This Model Shows These Result?
#1

(This post was last modified: 06-13-2022, 04:21 AM by luckmoshy.)

Hi, gentle buddies Here I face this issue on this model where is wrong? thank you

PHP Code:
<?php

namespace App\Models;

//KitchenWares business logic Table

/*
*Table id == kitchen_id
*table key == spoons
*table key == bowls
*table key == plates
*/

use App\Models\KitchenWaresModel as SpoonModel;
use 
App\Models\KitchenWaresModel as BowlsModel;
use 
App\Models\KitchenWaresModel as PlatesModel;

class 
KitchenWaresController extends BaseController
{
//private ....
 
public function __construct() {
     
$this->SpoonModel = new SpoonModel(); 
          
$this->BowlsModel = new BowlsModel(); 
     
$this->PlatesModel = new PlatesModel(); 

     } 
    public function spoon($spoons null)
    {
 
//here it shows nothing
 
 
$data['show_spoon']= $this->SpoonModel->where('spoons',$spoons)->orderBy('datetime','DESC')->findAll();

        return view('kitchen/spoon',$data);
    }

    public function bowls($bowls null)
    {            //here it shows data from  SpoonModel
 
$data['show_bowls']= $this->BowlsModel->where('bowls',$bowls)->orderBy('datetime','DESC')->findAll(12);

              return view('kitchen/bowl',$data);

    }
 public function 
plates($plates =null)
    {                //here it shows data from  BowlsModel

 
$data['show_plate']= $this->PlatesModel->where('plates',$plates)->orderBy('datetime','DESC')->findAll();
 
            return view('kitchen/plate',$data);

    }

/*
*It works fine but with a different result 
*/
/*
//The same as here???!!!
public function spoon($spoon = false)
{
    if ($spoon === false) {
        return $this->findAll();
    }

    return $this->asArray()
                ->where(['spoon' => $spoon])
                ->first();
}
*/ 
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#2

I don’t quite understand why create three instances of a class. Your methods have unique names, and database queries have unique conditions.
After querying the database, the state of the query builder is reset, which means that the conditions of the first query will not be applied to subsequent ones.
Reply
#3

Verify the table property on each model and make sure they point to the correct table.
Reply
#4

(This post was last modified: 06-13-2022, 11:40 PM by luckmoshy.)

(06-13-2022, 05:08 PM)kilishan Wrote: Verify the table property on each model and make sure they point to the correct table.


Thank @kilishan I have verified this table first there were typos on the spell now is working fine in all results but interchangeably mean vise-versa @spoon products result to @bowls products and bowls product result in plate products even though it is working fine but is not really working in unique columns as targeted

(06-13-2022, 07:49 AM)iRedds Wrote: I don’t quite understand why to create three instances of a class. Your methods have unique names, and database queries have unique conditions.
After querying the database, the state of the query builder is reset, which means that the conditions of the first query will not be applied to subsequent ones.

Thank you @iRedds my real point I wanted to use a single table and get results from the unique table by the point i wanted to use with (VIEW_CELL) as result products should all depend on a single table with a unique key even though it is working fine but result come vise verse mean @spoon key result product to other @key instead of what result asked that was my wonder Why
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#5

What if the problem is while adding records to the table?
Reply
#6

(This post was last modified: 06-14-2022, 02:49 AM by luckmoshy.)

Thank you so many guys by far I have come across and found by using query builder and(Generating Query Results) it is working fine with no problem but CI MODEL gives me that scenario. at the moment have solved it by using query builder now everything working fantastically
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply




Theme © iAndrew 2016 - Forum software by © MyBB