本文整理汇总了PHP中Movie::find_by_sql方法的典型用法代码示例。如果您正苦于以下问题:PHP Movie::find_by_sql方法的具体用法?PHP Movie::find_by_sql怎么用?PHP Movie::find_by_sql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Movie
的用法示例。
在下文中一共展示了Movie::find_by_sql方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find_movies
public static function find_movies($user_id = 0)
{
global $database;
$sql = "SELECT m.* FROM movies m INNER JOIN alerts a ON a.id = m.id WHERE a.user_id = {$user_id}";
$movies = Movie::find_by_sql($sql);
foreach ($movies as $movie) {
if ($alert = static::find($user_id, $movie->id)) {
$movie->alert = $alert;
}
}
return !empty($movies) ? $movies : false;
}
示例2: sendResponse
<?php
require_once "../includes/initialize.php";
// require key and id parameter.
if (empty($_GET['q']) || empty($_GET['key'])) {
sendResponse(400, "Invalid request. Please provide \"q\" and \"key\" parameters.");
} else {
if ($_GET['key'] != API_KEY) {
sendResponse(403, "Invalid API key.");
} else {
$searchTerm = $database->escape_value($_GET['q']);
$sql = "SELECT * FROM movies WHERE title LIKE '% {$searchTerm}%' OR title LIKE '{$searchTerm}%' ORDER BY popularity DESC LIMIT 6";
$movies = Movie::find_by_sql($sql);
$results = array();
foreach ($movies as $movie) {
$results[] = $movie->export();
}
$popular = array("movies" => $results);
sendResponse(200, json_encode($popular));
}
}