if (is_array($search_words)) {
reset($search_words);
$search = implode(' ', $search_words);
$select_where->where('MATCH(artist,title) AGAINST (?)', $search);
/*while (list($key, $val) = each($search_words)) {
$val = "%$val%";
$orWhere[] = $db->quoteInto('(title like ?)', $val) . ' OR ' .
$db->quoteInto('(artist like ?)', $val) . ' OR ' .
$db->quoteInto('(album like ?)', $val);
}
$select_where->where(implode(' OR ', $orWhere)); */
}
if ($sort_letter == '0 - 9') {
$select_where->where($db->quoteInto('NOT((artist>=?)', 'A') . ' AND ' . $db->quoteInto('(artist))', 'ZZZZZZZZZZZ'));
} elseif ($sort_letter != '') {
$nextletter = chr(ord($sort_letter) + 1);
$select_where->where($db->quoteInto('(artist>=?)', $sort_letter) . ' AND ' . $db->quoteInto('(artist)', $nextletter));
}
//Calculate total
$total_select = clone $select_where;
$total_select->from('songlist',
array('cnt' => 'count(*)'));
try {
$row = $db->fetchRow($total_select);
} catch (Zend_Db_Adapter_Exception $ex) {
echo "Please verify database settings.
";
exit;
}
self::$playlistSongCount = $row['CNT'];
//Now grab a section of that
$playlist_select = $select_where;
if (is_array($search_words))
{
$select_where->from('songlist', array
(
'*',
'relevance' => $db->quoteInto('MATCH(songlist.artist,title) AGAINST (?)', $search))
)
->order('relevance DESC');
} else {
$playlist_select->from('songlist')
->order(array('artist ASC', 'title ASC'))
->limit($limit, $start);
}
try {
$rows = $db->fetchAll($playlist_select);
$songs = array();
foreach ($rows as $key => $row) {
$songs[$key] = new self();
$songs[$key]->setValues($row);
}
} catch (Zend_Db_Adapter_Exception $ex) {
echo "Please verify database settings.
";
exit;
}
return $songs;
}