ScorpionGhost
Создатель
- Регистрация
- 26 Мар 2010
- Сообщения
- 42
- Реакции
- 1
- Автор темы
- #1
Люди знающие, помогите пожалуйста вывести в шаблоне poll_results.html данные из столбца v_rank таблицы _poll_variants. Чтобы напротив каждого ответа выводилось соответствующее ему значение v_rank.
Не могу сообразить, что написать в class.PollPrototype.php, насколько я понимаю, надо прописать в :
// функция для показа результатов опроса по id
function show_stats($poll_id = null) {
global $CONFIG, $db, $tpl, $server, $lang, $baseurl;
$poll_id = (int)$poll_id;
if (!$poll_id) return FALSE;
$variants = array();
$results = array();
$max_width = 400;
$sum = 0;
$max = 0;
$max_element_id = 0;
$PV = new CPollVariants_DB($this->table_prefix."_poll_variants", "id");
$temp = $PV->stats($poll_id);
$db->query("SELECT id,variant_text
FROM ".$this->table_prefix."_poll_other_results
WHERE poll_id=".$poll_id."
ORDER BY variant_text");
$first_record = true;
while ($db->next_record()) {
if (!$first_record && $last_text == $db->f('variant_text')) {
$idx = sizeof($others) - 1;
$others[$idx]["count"]++;
$others[$idx]["ids"] .= ",".$db->f('id');
} else {
$first_record = false;
$last_text = $db->f('variant_text');
$others[] = array(
"variant_text" => $last_text,
"count" => 1,
"ids" => $db->f('id'),
);
}
}
if (count($temp) > 0 || is_array($others)) {
if (count($temp) > 0) {
foreach($temp as $idx => $v) {
$variants[$v["variant_id"]] = $v["variant"];
$results[$v["variant_id"]] = intval($v["result"]);
$sum += $results[$v["variant_id"]];
if ($results[$v["variant_id"]] > $max) {
$max = $results[$v["variant_id"]];
$max_element_id = $v["variant_id"];
}
}
}
if (is_array($others)) {
$others_cnt = 0;
foreach($others as $idx => $v) {
$others_cnt += $v["count"];
}
$variants["others"] = $this->_msg["Another_answer"];
$results["others"] = $others_cnt;
$sum += $results["others"];
if ($results["others"] > $max) {
$max = $results["others"];
$max_element_id = "others";
}
}
$one_percent_votes = $sum / 100;
$gif_width = ($max_element_id) ? round(($results[$max_element_id] / $one_percent_votes) * 4) + 20 : 20;
$cnt_variants = sizeof($variants);
$last_proc = 100;
foreach ($variants as $v_id => $variant) {
if ($sum) {
$result = round($results[$v_id] / $one_percent_votes);
$cnt_variants--;
if ($cnt_variants == 0) {
$result = $last_proc;
}
$last_proc -= $result;
$width = round($result * 4);
} else {
$result = 0;
$width = 0;
}
$tpl->newBlock('block_results');
$tpl->assign(array(
variant => ($v_id=='others') ? $this->_msg['Another_answer'] :$variant,
result => $result.'%',
vote => $results[$v_id],
width => $width + 1,
gif_width => $gif_width,
vgif_width => $gif_width.' '.$width,
));
}
if (is_array($others)) {
$tpl->newBlock('block_other_results');
$tpl->assign(Array(
"MSG_Another_answers" => $this->_msg["Another_answers"],
));
foreach($others as $idx => $v) {
$tpl->newBlock('block_other_result');
$tpl->assign(Array(
"MSG_Confirm_delete_this_answer" => $this->_msg["Confirm_delete_this_answer"],
"MSG_Delete" => $this->_msg["Delete"],
));
$tpl->assign(array(
variant => ($v["variant_text"]) ? htmlspecialchars($v["variant_text"]) : "«" . $this->_msg["Without_variant"] . "»",
vote => $v["count"],
variant_del_link => $baseurl."&action=del_variant&ids=".$v["ids"],
));
}
}
return TRUE;
}
return FALSE;
}
но у меня не получается
Заранее благодарен за помощь
Не могу сообразить, что написать в class.PollPrototype.php, насколько я понимаю, надо прописать в :
// функция для показа результатов опроса по id
function show_stats($poll_id = null) {
global $CONFIG, $db, $tpl, $server, $lang, $baseurl;
$poll_id = (int)$poll_id;
if (!$poll_id) return FALSE;
$variants = array();
$results = array();
$max_width = 400;
$sum = 0;
$max = 0;
$max_element_id = 0;
$PV = new CPollVariants_DB($this->table_prefix."_poll_variants", "id");
$temp = $PV->stats($poll_id);
$db->query("SELECT id,variant_text
FROM ".$this->table_prefix."_poll_other_results
WHERE poll_id=".$poll_id."
ORDER BY variant_text");
$first_record = true;
while ($db->next_record()) {
if (!$first_record && $last_text == $db->f('variant_text')) {
$idx = sizeof($others) - 1;
$others[$idx]["count"]++;
$others[$idx]["ids"] .= ",".$db->f('id');
} else {
$first_record = false;
$last_text = $db->f('variant_text');
$others[] = array(
"variant_text" => $last_text,
"count" => 1,
"ids" => $db->f('id'),
);
}
}
if (count($temp) > 0 || is_array($others)) {
if (count($temp) > 0) {
foreach($temp as $idx => $v) {
$variants[$v["variant_id"]] = $v["variant"];
$results[$v["variant_id"]] = intval($v["result"]);
$sum += $results[$v["variant_id"]];
if ($results[$v["variant_id"]] > $max) {
$max = $results[$v["variant_id"]];
$max_element_id = $v["variant_id"];
}
}
}
if (is_array($others)) {
$others_cnt = 0;
foreach($others as $idx => $v) {
$others_cnt += $v["count"];
}
$variants["others"] = $this->_msg["Another_answer"];
$results["others"] = $others_cnt;
$sum += $results["others"];
if ($results["others"] > $max) {
$max = $results["others"];
$max_element_id = "others";
}
}
$one_percent_votes = $sum / 100;
$gif_width = ($max_element_id) ? round(($results[$max_element_id] / $one_percent_votes) * 4) + 20 : 20;
$cnt_variants = sizeof($variants);
$last_proc = 100;
foreach ($variants as $v_id => $variant) {
if ($sum) {
$result = round($results[$v_id] / $one_percent_votes);
$cnt_variants--;
if ($cnt_variants == 0) {
$result = $last_proc;
}
$last_proc -= $result;
$width = round($result * 4);
} else {
$result = 0;
$width = 0;
}
$tpl->newBlock('block_results');
$tpl->assign(array(
variant => ($v_id=='others') ? $this->_msg['Another_answer'] :$variant,
result => $result.'%',
vote => $results[$v_id],
width => $width + 1,
gif_width => $gif_width,
vgif_width => $gif_width.' '.$width,
));
}
if (is_array($others)) {
$tpl->newBlock('block_other_results');
$tpl->assign(Array(
"MSG_Another_answers" => $this->_msg["Another_answers"],
));
foreach($others as $idx => $v) {
$tpl->newBlock('block_other_result');
$tpl->assign(Array(
"MSG_Confirm_delete_this_answer" => $this->_msg["Confirm_delete_this_answer"],
"MSG_Delete" => $this->_msg["Delete"],
));
$tpl->assign(array(
variant => ($v["variant_text"]) ? htmlspecialchars($v["variant_text"]) : "«" . $this->_msg["Without_variant"] . "»",
vote => $v["count"],
variant_del_link => $baseurl."&action=del_variant&ids=".$v["ids"],
));
}
}
return TRUE;
}
return FALSE;
}
но у меня не получается

Заранее благодарен за помощь