1

I want to get agama with the count of pegawai with same as propinsisID and agamaID this is my controller, but i get this error Error Syntax error or access violation Please help me.. Sorry for Bad English

public function getPropinsi($id)
{
    $this->data['query'] =  DB::table("propinses")->where("id",$id)->first();
    $this->data['title'] = $this->data['query']->Propinsi;
    $this->data['count_satker'] = DB::table('satkerfakes')->where('PropinsiID',$id)->count(); 
    $this->data['pegawai'] = Pegawais::where('PropinsiID',$id);
    $this->data['agama'] = DB::table("agamas")
                                    ->select("agamas.Agama",DB::raw("(select count(*) 
                                        from pegawais 
                                        where pegawais.PropinsiID = $id
                                        where pegawais.AgamaID = agamas.AgamaID) as total_pegawai"))->get();
    return view('index.propinsi',$this->data);
}

1 Answer 1

1

You have at least 2 errros here:

$this->data['pegawai'] = Pegawais::where('PropinsiID',$id);

What yo want to achieve here? If you want to get record with this id, you should use:

$this->data['pegawai'] = Pegawais::where('PropinsiID',$id)->get();

or

$this->data['pegawai'] = Pegawais::where('PropinsiID',$id)->first();

depending whether you want to get 1 record or more.

And in your query you use:

select count(*)  from pegawais 
    where pegawais.PropinsiID = $id
    where pegawais.AgamaID = agamas.AgamaID) as total_pegawai

You cannot user where twice, you should use AND operator:

select count(*)  from pegawais 
    where pegawais.PropinsiID = $id
    AND pegawais.AgamaID = agamas.AgamaID) as total_pegawai
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.