Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,694 Points

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

Simon Coates
Simon Coates
28,694 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.