SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 30
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    class undefined any suggestion?

    The output of the class in this html is undefined can anybody tell me what can be done to define?

    HTML Code:
    <td>
    <ul id="Torpedo" class="undefined">
    <li class="one">
    <a title="1 Star" href="javascript:RateItem('Torpedo', 1);">1</a>
    </li>
    <li class="two">
    <a title="2 Stars" href="javascript:RateItem('Torpedo', 2);">2</a>
    </li>
    <li class="three">
    <a title="3 Stars" href="javascript:RateItem('Torpedo', 3);">3</a>
    </li>
    <li class="four">
    <a title="4 Stars" href="javascript:RateItem('Torpedo', 4);">4</a>
    </li>
    <li class="five">
    <a title="5 Stars" href="javascript:RateItem('Torpedo', 5);">5</a>
    </li>
    </ul>
    </td>

  2. #2
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    be more specify please

    may be this class name is undefined in php,asp or whatever you have

  3. #3
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume this html output was produced by a php script? and the php script set the class name of the list with id="Torpedo" to class="undefined". If yes, then there is no problem at all. You can now use the class to style any list with that class name on your page the same way, or you can use the #Torpedo to style this one list very specific.

    On the other hand, if you want that class name to say defined because it needs to be styled the way other lists with that class name are styled, then we need the php code that produced that html output.

    Or if it wasn't a php script that produced that html output, than by all means change it by hand, and name it any way you want it, and then style it in your stylesheet.

    To sum it up, as 2bee said, be more specific about:

    1. what you have there
    2. what you want to achieve

  4. #4
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php

    PHP Code:
       if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $classes      "rating " Rating::ShowStars($averageStars);
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\"><a   href=\"javascript:RateItem('{$varItem}', 1);\" title=\"1 Star\">1</a></li>\r\n";
                
    $output .= "  <li class=\"two\"><a   href=\"javascript:RateItem('{$varItem}', 2);\" title=\"2 Stars\">2</a></li>\r\n";
                
    $output .= "  <li class=\"three\"><a href=\"javascript:RateItem('{$varItem}', 3);\" title=\"3 Stars\">3</a></li>\r\n";
                
    $output .= "  <li class=\"four\"><a  href=\"javascript:RateItem('{$varItem}', 4);\" title=\"4 Stars\">4</a></li>\r\n";
                
    $output .= "  <li class=\"five\"><a  href=\"javascript:RateItem('{$varItem}', 5);\" title=\"5 Stars\">5</a></li>\r\n";
                
                
    $output .= "</ul>\r\n";
              }
              else
              {
                
    $classesd      "rated " Rating::ShowStars($averageStars);
                
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classesd}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\">1</li>\r\n";
                
    $output .= "  <li class=\"two\">2</li>\r\n";
                
    $output .= "  <li class=\"three\">3</li>\r\n";
                
    $output .= "  <li class=\"four\">4</li>\r\n";
                
    $output .= "  <li class=\"five\">5</li>\r\n";                                    
                
    $output .= "</ul>\r\n";
              } 
    look at the else statement from there is where the css class is coming undifined I am using firebug and it is not picking it up. unless I refresh the browser manually. When i refresh the browser manually then it picks up and works perfectly but I want it to go directly to the code below instead of refreshing it manually each time I rate an item or an user rate an item.
    <td>
    <ul id="Torpedo" class="rated threestar">
    <li class="one">1</li>
    <li class="two">2</li>
    <li class="three">3</li>
    <li class="four">4</li>
    <li class="five">5</li>
    </ul>
    </td>
    for reference belows are the details of the medhod RateItem and ShowStars in case the issue causing the trigger of that undefined class comes from one of the other method used in the "OutputRating" the first script of this post.

    RateItem method
    PHP Code:
     public static function RateItem($varItem$varRating$varClasses)
          {
            
    $newClassNames $varClasses;
            
            
    // Verify $varName was provided
            
    if ($varItem != null && strlen(trim($varItem)) != 0
              
    && $varRating != null && strlen(trim($varRating)) != && is_numeric($varRating
              && 
    $varClasses != null && strlen(trim($varClasses)) != 0)
            {
              
    // Check if Magic Quotes is ON
              
    if (!get_magic_quotes_gpc())
              {
                
    $varItem addslashes($varItem);
              }
              
              
    // Check to see that the user has not already rated this item
              
    if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $ipAddress $_SERVER['REMOTE_ADDR'];
                
                
    Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$varItem}', {$varRating}, '{$ipAddress}', NOW())""InsertRating");
                
    Database::FetchResults("InsertRating");
                
    Database::FreeResults("InsertRating");
                
    Database::RemoveSavedResults("InsertRating");
                
                
    // Information for the Output
                
    $averageStars  Rating::CalculateAverageRating($varItem);
                
    $newClassNames "rated " Rating::ShowStars($averageStars);
              }
            }
            else
            {
              
    // This is a major issue. NOT enough information was sent to log the item
              
    Error::LogError("Variable(s) Missing""You must provide all of the information to log the rating of this item.");
            }
            
            
    // Build Name/Value Pair to return
            
    $nameValue "classes={$newClassNames}&item={$varItem}";
            return 
    $nameValue;
          } 
    Check
    $newClassNames = "rated " . Rating::ShowStars($averageStars);
    on the RateItem, whatever is cuasing the undefined class issue can could be coming from there.

    ShowStar Method:
    1 way I have it scripted
    PHP Code:
    // Show Stars
          // Returns the class information for the number of stars to show
    private static function ShowStars($varStars)
          {
    $classes '';        // Select the Number of Stars Class
            
    switch ($varStars)
            {
            
              case 
    1:
                
    $classes .= "onestar";
                break;
              case 
    2:
                
    $classes .= "twostar";
                break;
              case 
    3:
                
    $classes .= "threestar";
                break;
              case 
    4:
                
    $classes .= "fourstar";
                break;
              case 
    5:
                
    $classes .= "fivestar";
                break;
              default:
                
    $classes .= "nostar";
                break;
            }
            
            return 
    $classes;
          } 
    Second way ShowStars Method is scripted either or could be used this second way worked once but no anymore.

    PHP Code:
        private static function ShowStars($varStars)
    {
        
    $aStars = array(
            
    1    =>    'onestar',
            
    2    =>    'twostar',
            
    3    =>    'threestar',
            
    4    =>    'fourstar',
            
    5    =>    'fivestar'
        
    );
        return (
    true === array_key_exists((integer)$varStars$aStars)) ? $aStars[(integer)$varStars] : 'nostar' ;

    The first and the second way has the same result but right now it seem that this method is not what's causing the issue producing this undefined class in the html ouput.

  5. #5
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unless I refresh the browser manually
    This is what I don't get. It may be just a cache issue.

  6. #6
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to print Screen this issue so you guys can see it but i am getting some trouble shooting loading the images to the forum wait some time until i post the images so you see it in images..

  7. #7
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is a rating system that I am working on Right now the nostar row stars appear when there is not any rating or any user or IP.

    Stage 1 before user x click there is not votes, in other words the item will be rated for the first time and the stars appear blank





    Stage 2
    The user x clicked in one of the star in this Case Nike Air Jordan item was


    Stage 3
    Then stage 3 will only be possible if i click the refresh button of the firefox browser.




    The final result should be from stage 1 to stage 2 without having to click the refresh button. But right now that's the output and i don't know what is causing it.
    Last edited by co.ador; Jul 24, 2009 at 17:42.

  8. #8
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okay, I got it now, well I understand the issue now, but it gives me some headaches. Somehow, I still feel that there is something missing somewhere. Mind you, I'm not that proficient with Javascript/php as I'm with html/css, so you might have better chances somewhere else on Sitepoint.

    But anyway, what exactly is triggered by the javascript, and then where does it feed back? The undefined must come from somewhere but I don't see this in your current code. I have a feeling that the error is somewhere in the javascript code rather than in the php code.

    Just to clarify, that first php box, is that from the actual page or is that located somewhere else?

  9. #9
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $classes      "rating" Rating::ShowStars($averageStars);
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\"><a   href=\"javascript:RateItem('{$varItem}', 1);\" title=\"1 Star\">1</a></li>\r\n";
                
    $output .= "  <li class=\"two\"><a   href=\"javascript:RateItem('{$varItem}', 2);\" title=\"2 Stars\">2</a></li>\r\n";
                
    $output .= "  <li class=\"three\"><a href=\"javascript:RateItem('{$varItem}', 3);\" title=\"3 Stars\">3</a></li>\r\n";
                
    $output .= "  <li class=\"four\"><a  href=\"javascript:RateItem('{$varItem}', 4);\" title=\"4 Stars\">4</a></li>\r\n";
                
    $output .= "  <li class=\"five\"><a  href=\"javascript:RateItem('{$varItem}', 5);\" title=\"5 Stars\">5</a></li>\r\n";
                
    $output .= "</ul>\r\n"
    this is what javascript triggers... in the code this is called the OutPutRating method and this is the only place I see where javascript is triggering some code..

    The whole code the Rating class.
    PHP Code:
    <?php
        
    class Rating
      
    {
        
    ## PRIVATE VARIABLES
        ## END PRIVATE VARIABLES

        ## PUBLIC METHODS
          // Output the Rating information
          // Returns a string of HTML
          
    public static function OutputRating($varItem)
          {
            
    // Verify $varItem was provided
            
    if ($varItem != null && strlen(trim($varItem)) != 0)
            {
              
    // Check if Magic QUotes is ON
              
    if (!get_magic_quotes_gpc())
              {
                
    $varItem addslashes($varItem);
              }
              
              
    // Information for the Output
              
    $averageStars Rating::CalculateAverageRating($varItem);
              
              
    // Check to see that the user has not already rated this item
              
    if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $classes      "rating" Rating::ShowStars($averageStars);
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\"><a   href=\"javascript:RateItem('{$varItem}', 1);\" title=\"1 Star\">1</a></li>\r\n";
                
    $output .= "  <li class=\"two\"><a   href=\"javascript:RateItem('{$varItem}', 2);\" title=\"2 Stars\">2</a></li>\r\n";
                
    $output .= "  <li class=\"three\"><a href=\"javascript:RateItem('{$varItem}', 3);\" title=\"3 Stars\">3</a></li>\r\n";
                
    $output .= "  <li class=\"four\"><a  href=\"javascript:RateItem('{$varItem}', 4);\" title=\"4 Stars\">4</a></li>\r\n";
                
    $output .= "  <li class=\"five\"><a  href=\"javascript:RateItem('{$varItem}', 5);\" title=\"5 Stars\">5</a></li>\r\n";
                
    $output .= "</ul>\r\n";
              }
              else
              {
                
    $classes      "rated " Rating::ShowStars($averageStars);
                
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\">1</li>\r\n";
                
    $output .= "  <li class=\"two\">2</li>\r\n";
                
    $output .= "  <li class=\"three\">3</li>\r\n";
                
    $output .= "  <li class=\"four\">4</li>\r\n";
                
    $output .= "  <li class=\"five\">5</li>\r\n";                                    
                
    $output .= "</ul>\r\n";
              }
            }
            else
            {
              
    $output "";
              
    // This is a major issue. NO information can be retrieve if an item name is not passed.
              
    Error::LogError("Variable Missing""You must provide the item name for this function to find the average.");
            }
            
            return 
    $output;
          }
          
          
    // Rate an Item
          // Returns the name/value pair of new class names and the item name
          
    public static function RateItem($varItem$varRating$varClasses)
          {
            
    $newClassNames $varClasses;
            
            
    // Verify $varName was provided
            
    if ($varItem != null && strlen(trim($varItem)) != 0
              
    && $varRating != null && strlen(trim($varRating)) != && is_numeric($varRating
              && 
    $varClasses != null && strlen(trim($varClasses)) != 0)
            {
              
    // Check if Magic Quotes is ON
              
    if (!get_magic_quotes_gpc())
              {
                
    $varItem addslashes($varItem);
              }
              
              
    // Check to see that the user has not already rated this item
              
    if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $ipAddress $_SERVER['REMOTE_ADDR'];
                
                
    Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$varItem}', {$varRating}, '{$ipAddress}', NOW())""InsertRating");
                
    Database::FetchResults("InsertRating");
                
    Database::FreeResults("InsertRating");
                
    Database::RemoveSavedResults("InsertRating");
                
                
    // Information for the Output
                
    $averageStars  Rating::CalculateAverageRating($varItem);
                
    $newClassNames "rated " Rating::ShowStars($averageStars);
              }
            }
            else
            {
              
    // This is a major issue. NOT enough information was sent to log the item
              
    Error::LogError("Variable(s) Missing""You must provide all of the information to log the rating of this item.");
            }
            
            
    // Build Name/Value Pair to return
            
    $nameValue "classes={$newClassNames}&item={$varItem}";
            return 
    $nameValue;
          }
        
    ## END PUBLIC METHODS
        
        ## PRIVATE METHODS
          // Calculate Average Rating
          // Returns the number of stars to show
          
    private static function CalculateAverageRating($varItem)
          {
            
    $averageStars 0;
            
            
    // Query Average Rating for a specific Item
            
    Database::ExecuteQuery("SELECT AVG(`rating`) AS `averageRating` FROM `rating` WHERE `item_name`='{$varItem}'""AverageRating");
            
    $results Database::FetchResults("AverageRating");
            
    Database::FreeResults("AverageRating");
            
    Database::RemoveSavedResults("AverageRating");
            
            
    // Round the Average into a Whole Number
            
    if (sizeof($results) == 1)
            {
              if (
    $results[0]['averageRating'] != null)
              {
                
    $averageStars round($results[0]["averageRating"], 0);
              }
            }
            else
            {
              
    // This is simply a warning, as it isn't vital if no results were found, as the item may be new.
              
    Error::LogWarning("Rating Data Missing""No entries were found for '{$varName}', this might be the first entry.");
            }
            
            return 
    $averageStars;
          }
          
          
    // Show Stars
          // Returns the class information for the number of stars to show
        
    private static function ShowStars($varStars)
    {
        
    $aStars = array(
            
    1    =>    'onestar',
            
    2    =>    'twostar',
            
    3    =>    'threestar',
            
    4    =>    'fourstar',
            
    5    =>    'fivestar'
        
    );
        return (
    true === array_key_exists((integer)$varStars$aStars)) ? $aStars[(integer)$varStars] : 'nostar' ;


          
    // Check Ratings By IP Address
          // Returns the number of ratings for an item by an ip address
          
    private static function CheckRatingsByIp($varItem)
          {
            
    $ipAddress $_SERVER['REMOTE_ADDR'];
            
            
    Database::ExecuteQuery("SELECT COUNT(*) AS `totalRatings` FROM `rating` WHERE `item_name`='{$varItem}' AND `ip_address`='{$ipAddress}'""AlreadyRated");
            
    $results Database::FetchResults("AlreadyRated");
            
    Database::FreeResults("AlreadyRated");
            
    Database::RemoveSavedResults("AlreadyRated");
            
            
    // Check to see that the user has not already rated this item
            
    if ($results != null && $results[0]['totalRatings'] != null)
            {
              return 
    $results[0]['totalRatings'];
            }
            
            return 
    0;
          }
        
    ## END PRIVATE METHODS
      
    }
    ?> \
    The code below is placed in another page and it pulled all the information from the rating class.

    PHP Code:
    Timberland:<?php
          $ratingData 
    Rating::OutputRating('carmelo');
          
          if (
    Error::HasErrors())
          {
            echo 
    Error::ShowErrorMessages();
            
    Error::ClearErrors();
          }
          else
          {
            echo 
    $ratingData;
          }
        
    ?>
    If you cannot help me at least i will ask you to help me how to formulate the question for the php or javascript forum.

  10. #10
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to clarify, there isn't anywhere any more Javascript, that javascript:RateItem('{$varItem}', 1); is all? There isn't anywhere a Javascript function called RateItem?

    Your best bet would be to post all your code, tell us the actual filenames straight above the code box, and those screenshots.

    I'm off to bed now.

  11. #11
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    C2UK have a good sleep

    Below are all the files that composed the working system at this moment. I will star with the rating.class.php file. From there there is a method called the OutputRating and it is in charge as i explained before to either present the empty row of star if the user hasn't rated the item or the row of star rated by that ip and the average of all the ip that has rated that item.

    Rating.class.php
    PHP Code:
    <?php
        
    class Rating
      
    {
        
    ## PRIVATE VARIABLES
        ## END PRIVATE VARIABLES

        ## PUBLIC METHODS
          // Output the Rating information
          // Returns a string of HTML
          
    public static function OutputRating($varItem)
          {
            
    // Verify $varItem was provided
            
    if ($varItem != null && strlen(trim($varItem)) != 0)
            {
              
    // Check if Magic QUotes is ON
              
    if (!get_magic_quotes_gpc())
              {
                
    $varItem addslashes($varItem);
              }
              
              
    // Information for the Output
              
    $averageStars Rating::CalculateAverageRating($varItem);
              
              
    // Check to see that the user has not already rated this item
              
    if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $classes      "rating" Rating::ShowStars($averageStars);
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\"><a   href=\"javascript:RateItem('{$varItem}', 1);\" title=\"1 Star\">1</a></li>\r\n";
                
    $output .= "  <li class=\"two\"><a   href=\"javascript:RateItem('{$varItem}', 2);\" title=\"2 Stars\">2</a></li>\r\n";
                
    $output .= "  <li class=\"three\"><a href=\"javascript:RateItem('{$varItem}', 3);\" title=\"3 Stars\">3</a></li>\r\n";
                
    $output .= "  <li class=\"four\"><a  href=\"javascript:RateItem('{$varItem}', 4);\" title=\"4 Stars\">4</a></li>\r\n";
                
    $output .= "  <li class=\"five\"><a  href=\"javascript:RateItem('{$varItem}', 5);\" title=\"5 Stars\">5</a></li>\r\n";
                
    $output .= "</ul>\r\n";
              }
              else
              {
                
    $classes      "rated " Rating::ShowStars($averageStars);
                
                
                
    // Write Output HTML for the Rating Data
                
    $output  "\r\n";
                
    $output .= "<ul class=\"{$classes}\" id=\"{$varItem}\">\r\n";
                
    $output .= "  <li class=\"one\">1</li>\r\n";
                
    $output .= "  <li class=\"two\">2</li>\r\n";
                
    $output .= "  <li class=\"three\">3</li>\r\n";
                
    $output .= "  <li class=\"four\">4</li>\r\n";
                
    $output .= "  <li class=\"five\">5</li>\r\n";                                    
                
    $output .= "</ul>\r\n";
              }
            }
            else
            {
              
    $output "";
              
    // This is a major issue. NO information can be retrieve if an item name is not passed.
              
    Error::LogError("Variable Missing""You must provide the item name for this function to find the average.");
            }
            
            return 
    $output;
          }
          
          
    // Rate an Item
          // Returns the name/value pair of new class names and the item name
          
    public static function RateItem($varItem$varRating$varClasses)
          {
            
    $newClassNames $varClasses;
            
            
    // Verify $varName was provided
            
    if ($varItem != null && strlen(trim($varItem)) != 0
              
    && $varRating != null && strlen(trim($varRating)) != && is_numeric($varRating
              && 
    $varClasses != null && strlen(trim($varClasses)) != 0)
            {
              
    // Check if Magic Quotes is ON
              
    if (!get_magic_quotes_gpc())
              {
                
    $varItem addslashes($varItem);
              }
              
              
    // Check to see that the user has not already rated this item
              
    if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $ipAddress $_SERVER['REMOTE_ADDR'];
                
                
    Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$varItem}', {$varRating}, '{$ipAddress}', NOW())""InsertRating");
                
    Database::FetchResults("InsertRating");
                
    Database::FreeResults("InsertRating");
                
    Database::RemoveSavedResults("InsertRating");
                
                
    // Information for the Output
                
    $averageStars  Rating::CalculateAverageRating($varItem);
                
    $newClassNames "rated " Rating::ShowStars($averageStars);
              }
            }
            else
            {
              
    // This is a major issue. NOT enough information was sent to log the item
              
    Error::LogError("Variable(s) Missing""You must provide all of the information to log the rating of this item.");
            }
            
            
    // Build Name/Value Pair to return
            
    $nameValue "classes={$newClassNames}&item={$varItem}";
            return 
    $nameValue;
          }
        
    ## END PUBLIC METHODS
        
        ## PRIVATE METHODS
          // Calculate Average Rating
          // Returns the number of stars to show
          
    private static function CalculateAverageRating($varItem)
          {
            
    $averageStars 0;
            
            
    // Query Average Rating for a specific Item
            
    Database::ExecuteQuery("SELECT AVG(`rating`) AS `averageRating` FROM `rating` WHERE `item_name`='{$varItem}'""AverageRating");
            
    $results Database::FetchResults("AverageRating");
            
    Database::FreeResults("AverageRating");
            
    Database::RemoveSavedResults("AverageRating");
            
            
    // Round the Average into a Whole Number
            
    if (sizeof($results) == 1)
            {
              if (
    $results[0]['averageRating'] != null)
              {
                
    $averageStars round($results[0]["averageRating"], 0);
              }
            }
            else
            {
              
    // This is simply a warning, as it isn't vital if no results were found, as the item may be new.
              
    Error::LogWarning("Rating Data Missing""No entries were found for '{$varName}', this might be the first entry.");
            }
            
            return 
    $averageStars;
          }
          
          
    // Show Stars
          // Returns the class information for the number of stars to show
        
    private static function ShowStars($varStars)
    {
        
    $aStars = array(
            
    1    =>    'onestar',
            
    2    =>    'twostar',
            
    3    =>    'threestar',
            
    4    =>    'fourstar',
            
    5    =>    'fivestar'
        
    );
        return (
    true === array_key_exists((integer)$varStars$aStars)) ? $aStars[(integer)$varStars] : 'nostar' ;


          
    // Check Ratings By IP Address
          // Returns the number of ratings for an item by an ip address
          
    private static function CheckRatingsByIp($varItem)
          {
            
    $ipAddress $_SERVER['REMOTE_ADDR'];
            
            
    Database::ExecuteQuery("SELECT COUNT(*) AS `totalRatings` FROM `rating` WHERE `item_name`='{$varItem}' AND `ip_address`='{$ipAddress}'""AlreadyRated");
            
    $results Database::FetchResults("AlreadyRated");
            
    Database::FreeResults("AlreadyRated");
            
    Database::RemoveSavedResults("AlreadyRated");
            
            
    // Check to see that the user has not already rated this item
            
    if ($results != null && $results[0]['totalRatings'] != null)
            {
              return 
    $results[0]['totalRatings'];
            }
            
            return 
    0;
          }
        
    ## END PRIVATE METHODS
      
    }
    ?> \
    Check the javascript:RateItem function which is found in the javascript file called rating.js below

    rating.js:
    function RateItem(varItemId, varRating)
    {
    var varOrigClassName = document.getElementById(varItemId).className;

    // Retrieve Ajax Feeds
    new Ajax.Request('ajax.rate.item.php',
    {
    method: 'post',
    parameters: {item: varItemId, rating: varRating, classes: varOrigClassName},
    onSuccess: ReloadRating,
    onFailure: RatingError
    }
    );
    }

    function ReadNameValuePairs(nameValuePair)
    {
    var trimspaces = /(\s)+/;
    var returnData = new Array();
    var pairs = nameValuePair.split('&');

    for (var i = 0; i < pairs.length; i++)
    {
    var pair = pairs[i].split('=');
    returnData[pair[0].replace(trimspaces, "")] = pair[1];
    }

    return returnData;
    }

    function ReloadRating(requestObj, jsonObj)
    {
    var newlines = /(\r\n|\r|\n)/;
    var returnData = ReadNameValuePairs(requestObj.responseText.replace(newlines, ""));

    document.getElementById(returnData['item']).className = returnData['classes'];
    var liObj = document.getElementById(returnData['item']).getElementsByTagName('a');

    for (var i = 0; i < liObj.length; i++)
    {
    liObj[i].onclick = function(){};
    }
    }

    function RatingError()
    {
    }
    Check the function RateItem right on top I really don't have any idea but I see the CSS class .rating but .rated is not found in any part of the script. I was wondering if that's the problem why is not refreshing the data to stage 1 to stage 3.

    This rating.js makes reference to ajax.rate.item.php file which is found inside the rating.js i will posted below in case it serves to the solution of this issue.

    ajax.rate.item.php
    PHP Code:
    <?php
      
    require_once("classes/include.all.php");
      
      
    // Check that the data was sent
      
    if (sizeof($_POST) == 0
        
    || $_POST['item'] == null
        
    || strlen(trim($_POST['item'])) == 0
        
    || $_POST['rating'] == null
        
    || strlen(trim($_POST['rating'])) == 0
        
    || $_POST['classes'] == null
        
    || strlen(trim($_POST['classes'])) == 0)
      {
        die(
    "You shouldn't be attempting to access this file in this manner.");
      }
      
      echo 
    Rating::RateItem($_POST['item'], $_POST['rating'], $_POST['classes']);
    ?>
    The file include.all.php in the ajax.rate.item.php calls the files error.class.php, database.class.php and the rating.class.php the first script on this post. it also define the database connection to the server and that's all there is

    PHP Code:
    <?php
      
    require_once("error.class.php");
      require_once(
    "database.class.php");
      require_once(
    "rating.class.php");
      
    Database::Initialize("mysql""localhost""3306""menu""root""poliferico");
    ?>
    there is another file used in this system and it is a javascript file call prototype.js and it seem to be a general file used by most java scripts to pull out functions from there.

    Prtotype.js

  12. #12
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is giving me a headache, can you post this in the Javascript forum just like this?

  13. #13
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    He did, and it's giving us a headache too.

    He needs to make a copy of it to a different location, and remove everything that's not directly involved in causing the problem.

    Once he has a minimal amount of code that demonstrates the problem, he might be able to figure out what needs to be done from there.

    If not, he has a good minimal package that others can investigate for him.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #14
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry guys I going crazy too. The thing is that I don't know where exactly is the problem I believe now that is a javascript problem but it might be something else I posted all the files that conform this rating system. the php, css, javascript and AJax files.

    Well Right now I am trying to find where the problem is and that's a headache Guys be patient please it is kind of hard.

  15. #15
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    The problem is that the ajax communication is setting the class name to "undefined"

    You call ajax.rate.item.php with the following set of parameters
    item: varItemId, rating: varRating, classes: varOrigClassName

    and after processing, you retrieve the data
    var newlines = /(\r\n|\r|\n)/;
    var returnData = ReadNameValuePairs(requestObj.responseText.replace(newlines, ""));

    and get the data called classes
    document.getElementById(returnData['item']).className = returnData['classes'];



    The first thing to do is to confirm that the ajax.rate.item.php file is being given the correct expected data, and is returning the desired output.

    Or in other words, check the input, check the output.

    Use Charles to monitor the communications and let us know how it goes.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #16
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is the ajax communication set between the rating.js and the ajax.rate.item.php?

  17. #17
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    co.ador, I'm just wondering what's the purpose? Are you doing this to learn ajax? Are you doing this to add to an existing script? Or do you built your own things? The reason I'm asking is, to me it looks like you are trying to reinvent the wheel here.

  18. #18
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am doing a web page and i want to implement this rating system inside the web page. And it is giving me a headache. this is a built script by cpradio but it need some modifications. Right now i am going to give the whole script to rayreese and he will upload it in his web server so we can all comment and make opinion about it.

  19. #19
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The issue was, that the return response from the ajaxCall was:
    "\classes=rated fourstar&item=felo"

    The reason for this is because there is a backslash at the end of 'rating.class.php'

    And so when you tried to access returnData['classes'] in the Javascript, it couldn't find the index in the object so it returned undefined.

    Solution: get rid of the last 2 characters of rating.class.php.

    Tip of the day: Leave out '?>' in your php file if all you're doing is defining a class, so that no output is printed to the browser. And make sure that you are receiving and posting the correct data between XHR ( ajax ) calls.
    Cross browser css bugs

    Dan Schulz you will be missed

  20. #20
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you I call you the Hero of a missplaced slash that gave us all a lot of headaches

  21. #21
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guys the same trouble that SoulScratch pointed is showing up again but this time It's for a different reason I think is not the backslash causing it again. I was having some suggestion on how to add the
    PHP Code:
    mysql_real_scape_string $_GET 
    function because it was not rating the items name that had encoding characters in it. For reference visit this thread http://www.sitepoint.com/forums/showthread.php?t=630137
    and read from post six and on when ScallioXTX and Larks comment on the issue.

    the original code in the script within rating.class.php file is

    PHP Code:
     Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$varItem}', {$varRating}, '{$ipAddress}', NOW())""InsertRating");
                
    Database::FetchResults("InsertRating");
                
    Database::FreeResults("InsertRating");
                
    Database::RemoveSavedResults("InsertRating"); 
    Then with ScallioXTX suggestion it would be

    PHP Code:
       Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('".mysql_real_escape_string($_GET['$varItem'])."')', {$varRating}, '{$ipAddress}', NOW())""InsertRating");
                
    Database::FetchResults("InsertRating");
                
    Database::FreeResults("InsertRating");
                
    Database::RemoveSavedResults("InsertRating"); 
    But then when I modify the script to ScallioXTX suggestion then the same issue that I have presented on post #7 of this thread comes up again.. Now I don't know if is a back slash or a single quote. I am sure the new cause of the same issue lay here
    PHP Code:
    ('".mysql_real_escape_string($_GET['$varItem'])."')', 

  22. #22
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Those single quotes around the variable don't seem right to me.

    Store the escape string in a temporary variable, and use var_dump to see what's there.

    Code php:
    $escapedVarItem = mysql_real_escape_string($_GET[$varItem]);
    var_dump($escapedVarItem); die();

    Show us the info if you're not sure it's okay.

    If it looks right, use the escapedVarItem value in the database code instead, until you can get it working. Once the problem is resolved, you can then, with a greater understanding of things, move code from the variable declaration back in to the database once again.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  23. #23
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
      if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $ipAddress $_SERVER['REMOTE_ADDR'];
                
    $escapedVarItem mysql_real_escape_string($_GET[$varItem]);
    var_dump($escapedVarItem); die();
                
    Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$escapedVarItem}', {$varRating}, '{$ipAddress}', NOW())""InsertRating");
                
    Database::FetchResults("InsertRating");
                
    Database::FreeResults("InsertRating");
                
    Database::RemoveSavedResults("InsertRating"); 
    I have apply the var_dump and everything looks allright in the code but it still doesn't rate the especial character encoding item names it just rate the ones that don't use character encoding

  24. #24
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    What sort of character encoding is being used on the ones that fail.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  25. #25
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
      if (Rating::CheckRatingsByIp($varItem) == 0)
              {
                
    $ipAddress $_SERVER['REMOTE_ADDR'];
                
    $escapedVarItem mysql_real_escape_string($_GET[$varItem]);
    var_dump($escapedVarItem); die();
                
    Database::ExecuteQuery("INSERT INTO `rating` (`item_name`, `rating`, `ip_address`, `date_rated`) VALUES ('{$escapedVarItem}', {$varRating}, '{$ipAddress}', NOW())""InsertRating");
                
    Database::FetchResults("InsertRating");
                
    Database::FreeResults("InsertRating");
                
    Database::RemoveSavedResults("InsertRating"); 
    I have apply the var_dump and everything looks al lright in the code but it still doesn't rate the especial character encoding item names it just rate the ones that don't use character encoding


Bookmarks

Posting Permissions

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