Search This Blog

Wednesday, May 16, 2012

Easily finding an entry in your database activity

Here is a nice sql query to find an entry in your database activity, while searching for a specific text string:


$query = "SELECT * FROM {data_content} c JOIN {data_records} r ON r.id = c.recordid WHERE r.dataid=? AND c.content=?";
if($results = $DB->get_records_sql($query, array($data->id, 'my search string')))
{
    // do something here with results
}

It's a nice snippet!