I'm trying to get a video from my video database, the selection is based on a unique combination of external_id
and language_id
(both integers). I tried the following code, but it looks like findFirst()
only picks up the first criterium
$video = Video::findFirst("language_id=" . $language->id . " and external_id=" . $external->id);
Can anybody help me how to properly use findFirst with multiple criteria?
Try binding your parameters vs. concatenating them. Safer and it might identify an error area
$video = Video::findFirst(
[
'columns' => '*',
'conditions' => 'language_id = ?1 AND external_id = ?2',
'bind' => [
1 => $language->id,
2 => $external->id,
]
]
);
Both find() and findFirst() methods accept an associative array specifying the search criteria:
$robot = Robots::findFirst(array(
"type = 'virtual'",
"order" => "name DESC",
"limit" => 30
));
$robots = Robots::find(array(
"conditions" => "type = ?1",
"bind" => array(1 => "virtual")
));
// What's the first robot in robots table?
$robot = Robots::findFirst();
echo "The robot name is ", $robot->name, "\n";
// What's the first mechanical robot in robots table?
$robot = Robots::findFirst("type = 'mechanical'");
echo "The first mechanical robot name is ", $robot->name, "\n";
// Get first virtual robot ordered by name
$robot = Robots::findFirst(array("type = 'virtual'", "order" => "name"));
echo "The first virtual robot name is ", $robot->name, "\n";
continue reading here: Main Doc - Finding Records
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With