Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Integrating PHP with Databases Filtering Input for Queries Creating the Search Function

jinhwa yoo
jinhwa yoo
10,042 Points

help me

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); 

---> what does " LIMIT ? OFFSET ?" stands for ?? ---> what does this mean?? ---> what does "PDO::PARAM_STR" stands for ??

      $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;

}

if it tell me specifically, it will be great!! I will be understanding

Simon Coates
Simon Coates
28,693 Points

PDO::PARAM_STR tells bindParam the type of the value being bound into the SQL query. see here.

Simon Coates
Simon Coates
28,693 Points

with " LIMIT ? OFFSET ?", the question marks (?) are placeholders. They are where your parameters or values are used, when you use bind param or bind value methods. The documentation here and here shows some example and options.