Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    Feb 2015
    Posts
    1
    Member #
    44103

    5 star review system

    I have a 5 star review widget div that I wanted to place into the top caption slider of an image but it doesn't seem to work. I was using a span tag inside of the caption and it will show up sometimes but not properly and I can't seem to get it to scale to 30% of the caption or fix it to the top left of the caption.On the bottom caption I will have a buy button but that should be easy to fix once I get the top div sorted.

    The other problem I have is getting the vote data to work. I'm using php for that which I can't seem to get into fiddle(first time using it, sorry ) so I'll paste the php here.

    Here's a link to the fiddle: Edit fiddle - JSFiddle

    I can't seem to get php into the jfiddle so here's the php code:

    <?php

    $rating = new ratings($_POST['widget_id']);


    isset($_POST['fetch']) ? $rating->get_ratings() : $rating->vote();


    class ratings {

    private $data_file = './ratings.data.txt';
    private $widget_id;
    private $data = array();


    function __construct($wid) {

    $this->widget_id = $wid;

    $all = file_get_contents($this->data_file);

    if($all) {
    $this->data = unserialize($all);
    }
    }
    public function get_ratings() {
    if($this->data[$this->widget_id]) {
    echo json_encode($this->data[$this->widget_id]);
    }
    else {
    $data['widget_id'] = $this->widget_id;
    $data['number_votes'] = 0;
    $data['total_points'] = 0;
    $data['dec_avg'] = 0;
    $data['whole_avg'] = 0;
    echo json_encode($data);
    }
    }
    public function vote() {

    # Get the value of the vote
    preg_match('/star_([1-5]{1})/', $_POST['clicked_on'], $match);
    $vote = $match[1];

    $ID = $this->widget_id;
    # Update the record if it exists
    if($this->data[$ID]) {
    $this->data[$ID]['number_votes'] += 1;
    $this->data[$ID]['total_points'] += $vote;
    }
    # Create a new one if it doesn't
    else {
    $this->data[$ID]['number_votes'] = 1;
    $this->data[$ID]['total_points'] = $vote;
    }

    $this->data[$ID]['dec_avg'] = round( $this->data[$ID]['total_points'] / $this->data[$ID]['number_votes'], 1 );
    $this->data[$ID]['whole_avg'] = round( $this->data[$ID]['dec_avg'] );


    file_put_contents($this->data_file, serialize($this->data));
    $this->get_ratings();
    }

    # ---
    # end class
    }


    //function return_rating($raw_id) {
    //
    // $widget_data = fetch_rating($raw_id);
    // echo json_encode($widget_data);
    //}
    //
    //# Data is stored as:
    //# widget_id:number_of_voters:total_points:dec_avg:wh ole_avg
    //function fetch_rating($raw_id) {
    //
    // $all = file('./ratings.data.txt');
    //
    // foreach($all as $k => $record) {
    // if(preg_match("/$raw_id:/", $record)) {
    // $selected = $all[$k];
    // break;
    // }
    // }
    //
    // if($selected) {
    // $data = split(':', $selected);
    // $data[] = round( $data[2] / $data[1], 1 );
    // $data[] = round( $data[3] );
    // }
    // else {
    // $data[0] = $raw_id;
    // $data[1] = 0;
    // $data[2] = 0;
    // $data[3] = 0;
    // $data[4] = 0;
    // }
    //
    // return $data;
    //}
    //
    //
    //
    //
    //function register_vote() {
    //
    // preg_match('/star_([1-5]{1})/', $_POST['clicked_on'], $match);
    // $vote = $match[1];
    //
    // $current_data = fetch_rating($_POST['widget']);
    //
    // $new_data[] = $current_data['stars'] + $vote;
    // $new_data[] = $current_data['cast'] + 1;
    //
    //
    // # --> This needs to be fixed, since a widget ID is ALWAYS passed in
    // # it should be a class property
    // file_put_contents($_POST['widget'] . '.txt', " {$new_data[0]}\n{$new_data[1]}");
    //
    // return_rating($_POST['widget']);
    //}

    //foreach($all as $k => $record) {
    // if(preg_match("/$raw_id:/", $record)) {
    // $selected = $all[$k];
    // break;
    // }
    //}
    //
    //if($selected) {
    // $this->data = split(':', $selected);
    // $this->data[] = round( $this->data[2] / $this->data[1], 1 );
    // $this->data[] = round( $this->data[3] );
    //}
    //else {
    // $this->data[0] = $this->widget_id;
    // $this->data[1] = 0;
    // $this->data[2] = 0;
    // $this->data[3] = 0;
    // $this->data[4] = 0;
    //}

    ?>




    and here's the ratings.data.text:

    a:2:{s:2:"r1";a:5: {s:9:"widget_id";s:2:"r1";s:12:"number_votes";i:17 2;s:12:"total_points";i:553;s: 7:"dec_avg";d:3.2000000000000001776356839400250464 6778106689453125;s:9:"whole_avg";d:3;}s:2:"r2";a:4 :{s:12:"number_votes";i:90;s:12:"total_points";i:2 47;s:7:"dec_avg";d:2.70000000000000017763568394002 504646778106689453125;s:9:"whole_avg";d:3;}}


    If that's too vague please ask me anything All help is really appreciated

  2.  


Remove Ads

Posting Permissions

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

Tags for this Thread

All times are GMT -6. The time now is 08:46 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com