Reputation: 35
Good Afternoon, so I want to check if a specific value in my database is true on CakePHP.
My SQL table is called Oral and looks like this
---------------------
|PK|OralPresentation|
---------------------
|1 |1 |
---------------------
So what I want to do in my controller is to check if that Value is OralPresentation is 1.
I do so in the following code
$OralStatus = $this->Submission->query("SELECT * FROM Oral;");
//If Oral Presentations are activated
if($OralStatus['0']['PK']['OralPresentation']==1)
{
$this->set('Istrue','true'); //Passing this information to the view.
}
else
{
$this->set('Istrue','false');
}
}
Now when I echo isTrue in my view it always return false despite the database table being 1. Another Solution I have tried is in the IF statement
if($OralStatus['0']['PK']['OralPresentation'])
Upvotes: 0
Views: 585
Reputation: 35
$statusQuery = $this->Submission->query("SELECT * FROM oral WHERE PK = 1");
$this->set('status',$statusQuery['0']['oral']['OralPresentation']);
$status = $statusQuery['0']['oral']['OralPresentation'];
if($status['0']['oral']['OralPresentation']==1)
{
$this->set('Istrue',$status);
}
else
{
$this->set('Istrue',$status);
}
}
After trying a couple of solution based on other work I already had this worked. It is able to pass the value of the Database to the view
Upvotes: 0
Reputation: 1656
If you know the PK that you're trying to check, a handy way to do this would be to use field
.
$this->Oral->id = 1;
$Istrue = $this->Oral->field('OralPresentation'); // value for pk 1
$this->set(compact('Istrue'));
Upvotes: 0