CommonDBTM::find PHP Method

find() public method

Retrieve all items from the database
public find ( $condition = "", $order = "", $limit = "" ) : all
$condition condition used to search if needed (empty get all) (default '')
$order order field if needed (default '')
$limit limit retrieved datas if needed (default '')
return all retrieved data in a associative array by id
    function find($condition = "", $order = "", $limit = "")
    {
        global $DB;
        // Make new database object and fill variables
        $query = "SELECT *\n                FROM `" . $this->getTable() . "`";
        if (!empty($condition)) {
            $query .= " WHERE {$condition}";
        }
        if (!empty($order)) {
            $query .= " ORDER BY {$order}";
        }
        if (!empty($limit)) {
            $query .= " LIMIT " . intval($limit);
        }
        $data = array();
        if ($result = $DB->query($query)) {
            if ($DB->numrows($result)) {
                while ($line = $DB->fetch_assoc($result)) {
                    $data[$line['id']] = $line;
                }
            }
        }
        return $data;
    }
CommonDBTM