Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts

    [SOLVED] Advanced Poll modding question.

    Nevermind... I got it working.


    Hey,

    I'm using advanced poll 2 for a voting thing for my site and I want the options to be set as an id that will be pulled out of a database so i can change the names of people and I won't have to go back through all the records to change it.

    For example.

    Code:
    question - who is better?
    option 1 - 1
    option 2 - 3
    Then as it is displayed it pull the relating names from a database that would look like this

    Code:
    id          name
    1           chris
    2           john
    3           mark
    4           ben
    So the poll would display like this (o = radio button )

    Code:
    Who is better?
    o       Chris
    o       Mark
    The code that displays the poll is like this, if you need more of the code let me know.

    PHP Code:
    function get_poll_data($poll_id) {
            if (!isset(
    $this->options[$poll_id])) {
                
    $this->db->query("SELECT SUM(votes) as total FROM ".$this->tbl['poll_data']." WHERE (poll_id = '$poll_id')");
                
    $this->db->fetch_array($this->db->result);
                
    $this->options[$poll_id]['total'] = $this->db->record['total'];
                
    $this->db->query("SELECT * FROM ".$this->tbl['poll_data']." WHERE (poll_id = '$poll_id') ".$this->pollvars['result_order']);
                while (
    $this->db->fetch_array($this->db->result)) {
                    
    $option_id_arr[] = $this->db->record['option_id'];
                    
    $option_text_arr[] = $this->db->record['option_text'];
                    
    $option_votes_arr[] = $this->db->record['votes'];
                    
    $option_color_arr[] = $this->db->record['color'];
                }
                
    $this->options[$poll_id]['option_id'] = $option_id_arr;
                
    $this->options[$poll_id]['option_text'] = $option_text_arr;
                
    $this->options[$poll_id]['votes'] = $option_votes_arr;
                
    $this->options[$poll_id]['color'] = $option_color_arr;
                for (
    $i=0,$maxvote=0$i<sizeof($option_votes_arr); $i++) {
                    
    $maxvote = ($option_votes_arr[$i]>$maxvote) ? $option_votes_arr[$i] : $maxvote;
                }
                
    $this->options[$poll_id]['maxvote'] = $maxvote;
            }
            return 
    $this->options[$poll_id];
        }

        function 
    get_poll_option($poll_id) {
            if (!isset(
    $this->options_text[$poll_id])) {
                
    $query $this->db->query("SELECT option_id, option_text FROM ".$this->tbl['poll_data']." WHERE (poll_id = '$poll_id') order by option_id asc");
                while (
    $data $this->db->fetch_array($query)) {
                    
    $option_id_arr[] = $this->db->record['option_id'];
                    
    $option_text_arr[] = $this->db->record['option_text'];
                }
                
    $this->options_text[$poll_id]['option_id'] = $option_id_arr;
                
    $this->options_text[$poll_id]['option_text'] = $option_text_arr;
            }
            return 
    $this->options_text[$poll_id];
        }

        function 
    get_poll_question($poll_id) {
            if (!isset(
    $this->poll_question[$poll_id])) {
                
    $row $this->db->fetch_array($this->db->query("SELECT question FROM ".$this->tbl['poll_index']." WHERE (poll_id = '$poll_id')"));
                
    $this->poll_question[$poll_id] = htmlspecialchars($row['question']);
            }
            return 
    $this->poll_question[$poll_id];
        }

        function 
    display_poll($poll_id) {
            if (!isset(
    $this->poll_view_html[$poll_id]) || !isset($this->poll_view_html[$poll_id][$this->template_set])) {
                
    $pollvars $this->pollvars;
                if (!isset(
    $this->options_text[$poll_id])) {
                    
    $this->get_poll_option($poll_id);
                }
                
    $question $this->get_poll_question($poll_id);
                eval(
    "\$display_html = \"".$this->get_poll_tpl("display_head")."\";");
                
    $loop_html $this->get_poll_tpl("display_loop");
                for (
    $i=0;$i<sizeof($this->options_text[$poll_id]['option_id']);$i++) {
                    
    $data['option_text'] = $this->options_text[$poll_id]['option_text'][$i];
                    
    $data['option_id'] = $this->options_text[$poll_id]['option_id'][$i];
                    eval(
    "\$display_html .= \"$loop_html\";");
                }
                eval(
    "\$display_html .= \"".$this->get_poll_tpl("display_foot")."\";");
                
    $this->poll_view_html[$poll_id][$this->template_set] = $display_html;
            }
            return 
    $this->poll_view_html[$poll_id][$this->template_set];
        } 
    Thanks
    Last edited by SeeIT Solutions; 06-11-2005 at 08:48 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •