|
Гость
Гость
|
Задача состоит в том, чтобы из компонента Событий (Message2009) подмешивать некоторые из них в компонент с новостями (Message2001). Поскольку структура компонентов разная, равно как и имена полей, то приходится немного поработать напильником и сформировать свой запрос.
Вот код:
Код:
$f_photo_tpl = array(
'prefix' => "<div class='photos'>",
'record' => " <img src='%Path%' title='%Name%' alt='%Name%' />",
'divider' => " ",
'suffix' => "</div>",
'i' => 1
);
$ignore_all = 1;
$ignore_calc = 0;
$query_select = "a.`Message_ID`, a.`User_ID`, a.`IP`, a.`UserAgent`, a.`LastUser_ID`, a.`LastIP`, a.`LastUserAgent`, a.`Priority`, a.`Parent_Message_ID`, a.`ncTitle`, a.`ncKeywords`, a.`ncDescription`, sub.`Subdivision_ID`, CONCAT('', sub.`Hidden_URL`) AS `Hidden_URL`, cc.`Sub_Class_ID`, cc.`EnglishName`, a.`Checked`, a.`Created`, a.`Keyword`, a.`LastUpdated` + 0 AS LastUpdated, a.header, a.annotation, a.text, a.date, DATE_FORMAT(a.`date`,'%Y') as date_year, DATE_FORMAT(a.`date`,'%m') as date_month, DATE_FORMAT(a.`date`,'%d') as date_day, DATE_FORMAT(a.`date`,'%H') as date_hours, DATE_FORMAT(a.`date`,'%i') as date_minutes, DATE_FORMAT(a.`date`,'%s') as date_seconds, a.student";
$query_from = " (`Message2001` AS a) ";
$query_where = " sub.`Catalogue_ID` = '11' AND a.`Checked` = 1 AND a.student LIKE '%,2,%' ";
$query_join = "LEFT JOIN `Subdivision` AS sub ON sub.`Subdivision_ID` = a.`Subdivision_ID` LEFT JOIN `Sub_Class` AS cc ON cc.`Sub_Class_ID` = a.`Sub_Class_ID` ";
$query_where .= "UNION
SELECT a.`Message_ID`, a.`User_ID`, a.`IP`, a.`UserAgent`, a.`LastUser_ID`, a.`LastIP`, a.`LastUserAgent`, a.`Priority`, a.`Parent_Message_ID`, a.`ncTitle`, a.`ncKeywords`, a.`ncDescription`, sub.`Subdivision_ID`, CONCAT('', sub.`Hidden_URL`) AS `Hidden_URL`, cc.`Sub_Class_ID`, cc.`EnglishName`, a.`Checked`, a.`Created`, a.`Keyword`, a.`LastUpdated` + 0 AS LastUpdated, a.name as header, a.announce as annotation, a.description as text, a.`startDate` as date, DATE_FORMAT(a.`startDate`,'%Y') as date_year, DATE_FORMAT(a.startDate,'%m') as date_month, DATE_FORMAT(a.startDate,'%d') as date_day, DATE_FORMAT(a.startDate,'%H') as date_hours, DATE_FORMAT(a.startDate,'%i') as date_minutes, DATE_FORMAT(a.startDate,'%s') as date_seconds, a.student FROM (`Message2009` AS a) LEFT JOIN `Subdivision` AS sub ON sub.`Subdivision_ID` = a.`Subdivision_ID` LEFT JOIN `Sub_Class` AS cc ON cc.`Sub_Class_ID` = a.`Sub_Class_ID` WHERE a.`Parent_Message_ID` = '0' AND sub.`Catalogue_ID` = '11' AND a.`Checked` = 1 AND a.student LIKE '%,2,%'
ORDER BY `Created` DESC";
$result_vars = "\$f_RowID, \$f_User_ID, \$f_IP, \$f_UserAgent, \$f_LastUser_ID, \$f_LastIP, \$f_LastUserAgent, \$f_Priority, \$f_Parent_Message_ID, \$f_ncTitle, \$f_ncKeywords, \$f_ncDescription, \$f_Subdivision_ID, \$f_Hidden_URL, \$f_Sub_Class_ID, \$f_EnglishName, \$f_Checked, \$f_Created, \$f_Keyword, \$f_LastUpdated, \$f_header, \$f_annotation, \$f_text, \$f_date, \$f_date_year, \$f_date_month, \$f_date_day, \$f_date_hours, \$f_date_minutes, \$f_date_seconds ";
Вот сам запрос:
Код:SELECT SQL_CALC_FOUND_ROWS a.`Message_ID`, a.`User_ID`, a.`IP`, a.`UserAgent`, a.`LastUser_ID`, a.`LastIP`, a.`LastUserAgent`, a.`Priority`, a.`Parent_Message_ID`, a.`ncTitle`, a.`ncKeywords`, a.`ncDescription`, sub.`Subdivision_ID`, CONCAT('', sub.`Hidden_URL`) AS `Hidden_URL`, cc.`Sub_Class_ID`, cc.`EnglishName`, a.`Checked`, a.`Created`, a.`Keyword`, a.`LastUpdated` + 0 AS LastUpdated, a.header, a.annotation, a.text, a.date, DATE_FORMAT(a.`date`,'%Y') as date_year, DATE_FORMAT(a.`date`,'%m') as date_month, DATE_FORMAT(a.`date`,'%d') as date_day, DATE_FORMAT(a.`date`,'%H') as date_hours, DATE_FORMAT(a.`date`,'%i') as date_minutes, DATE_FORMAT(a.`date`,'%s') as date_seconds, a.student FROM (`Message2001` AS a) LEFT JOIN `Subdivision` AS sub ON sub.`Subdivision_ID` = a.`Subdivision_ID` LEFT JOIN `Sub_Class` AS cc ON cc.`Sub_Class_ID` = a.`Sub_Class_ID` WHERE sub.`Catalogue_ID` = '11' AND a.`Checked` = 1 AND a.student LIKE '%,2,%' UNION SELECT a.`Message_ID`, a.`User_ID`, a.`IP`, a.`UserAgent`, a.`LastUser_ID`, a.`LastIP`, a.`LastUserAgent`, a.`Priority`, a.`Parent_Message_ID`, a.`ncTitle`, a.`ncKeywords`, a.`ncDescription`, sub.`Subdivision_ID`, CONCAT('', sub.`Hidden_URL`) AS `Hidden_URL`, cc.`Sub_Class_ID`, cc.`EnglishName`, a.`Checked`, a.`Created`, a.`Keyword`, a.`LastUpdated` + 0 AS LastUpdated, a.name as header, a.announce as annotation, a.description as text, a.`startDate` as date, DATE_FORMAT(a.`startDate`,'%Y') as date_year, DATE_FORMAT(a.startDate,'%m') as date_month, DATE_FORMAT(a.startDate,'%d') as date_day, DATE_FORMAT(a.startDate,'%H') as date_hours, DATE_FORMAT(a.startDate,'%i') as date_minutes, DATE_FORMAT(a.startDate,'%s') as date_seconds, a.student FROM (`Message2009` AS a) LEFT JOIN `Subdivision` AS sub ON sub.`Subdivision_ID` = a.`Subdivision_ID` LEFT JOIN `Sub_Class` AS cc ON cc.`Sub_Class_ID` = a.`Sub_Class_ID` WHERE a.`Parent_Message_ID` = '0' AND sub.`Catalogue_ID` = '11' AND a.`Checked` = 1 AND a.student LIKE '%,2,%' ORDER BY `Created` DESC
В общем и целом все работает нормально, все выводится, однако:
1. Не работает навигация:
Код: if($totRows>$f_RowNum) {
<div>
<span>".opt_case($prevLink , "<a href='$prevLink'>Назад</a>","Назад")>."</span>
<span>".browse_messages($cc_env, 10)?></span>
<span>".opt_case($nextLink, "<a href='$nextLink'>Далее</a>","Далее")."</span>
</div>
}
2. Код Код: $f_photo->get_record(1) выдает ошибку в компоненте.
Так полагаю, что не определены переменные $f_photo, $totRows, $f_RowNum и др. Каким образом их можно определить при $ignore_all = 1 ?
NetCat Business версия 5.4
|