php - Query Database with Where Clause depending on array values


You must have seen this in WordPress, how you pass arguments to function and it queries the database depending on the arguments you have passed. If the arguments are not passed. It will nautically fall back to the default arguments. Exactly same thing I want to do here in my custom function.

 function get_module( $args = NULL ){
    $defaults = array(
        "module_id" => NULL,
        "module_slug" => NULL,
        "module_parent" => NULL,
        "module_status" => "publish"
    global $db;
    global $table_prefix;
    $sql = "SELECT * FROM $table_prefix" . "modules";
    $query = $db->SELECT($sql);
    return $db->FETCH_OBJECT();

People are also looking for solutions to the problem: php - Apache mod_rewrite query strings


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.