Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Let’s create the function that actually pulls the items using our search term.
Links
SQL Like Operator
SQL Wildcards
Example Code
function search_catalog_array($search, $limit = null, $offset = 0) {
include("connection.php");
try {
$sql = "SELECT media_id, title, category,img
FROM Media
WHERE title LIKE ?
ORDER BY
REPLACE(
REPLACE(
REPLACE(title,'The ',''),
'An ',
''
),
'A ',
''
)";
if (is_integer($limit)) {
$results = $db->prepare($sql . " LIMIT ? OFFSET ?");
$results->bindValue(1,"%".$search."%",PDO::PARAM_STR);
$results->bindParam(2,$limit,PDO::PARAM_INT);
$results->bindParam(3,$offset,PDO::PARAM_INT);
} else {
$results = $db->prepare($sql);
$results->bindValue(1,"%".$search."%",PDO::PARAM_STR);
}
$results->execute();
} catch (Exception $e) {
echo "Unable to retrieved results";
exit;
}
$catalog = $results->fetchAll();
return $catalog;
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
bryanlsantos
1,500 Points1 Answer
-
jlampstack
23,932 Points1 Answer
-
Aayushi Gupta
4,695 Points1 Answer
-
Qasim Hafeez
12,731 Points1 Answer
-
PLUS
Zachary Baker
Courses Plus Student 11,504 Points2 Answers
-
Žiga Krašovec
16,173 Points0 Answers
-
Igor Skoldin
6,779 Points0 Answers
-
jinhwa yoo
10,042 Pointshelp me
Posted by jinhwa yoojinhwa yoo
10,042 Points0 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up