Доброго времени суток. Подскажите пожалуйста, как изменить sql запрос ниже, чтоб получить в переменную параметр name с таблицы PREFIX . "_users с поиском по параметру user_id=extend_id где переменная extend_id с таблицы PREFIX . "_advice, все параметры получаю сейчас так {$row['extend_id']}?
$db->query("
SELECT
a.*,
a.id as ids,
u.*,
w.answer,
w.name as user_name,
w.time as times,
c.name as cats,
n.id,
n.title,
i.area,
i.images,
i.author,
i.advice_id,
s.descr as static_title,
s.name as static_alias
FROM " . PREFIX . "_advice as a
LEFT JOIN " . PREFIX . "_users as u ON (a.autor = u.name )
LEFT JOIN " . PREFIX . "_advice_answ as w ON (a.id = w.id)
LEFT JOIN " . PREFIX . "_advice_images as i ON (a.id = i.advice_id )
LEFT JOIN " . PREFIX . "_advice_cat as c ON (a.category = c.id)
LEFT JOIN " . PREFIX . "_post as n ON (n.id = a.extend_id AND a.extend_type = 'post')
LEFT JOIN " . PREFIX . "_static as s ON (s.id = a.extend_id AND a.extend_type = 'static')
WHERE a.moder='{$moder}' ORDER BY a.time DESC LIMIT $start_from, $news_per_page
");
Заранее спасибо за помощь.