vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   do you see anything wrong with this code? (https://vborg.vbsupport.ru/showthread.php?t=73453)

Guy G 12-29-2004 05:39 AM

do you see anything wrong with this code?
 
PHP Code:

//Rating clculation
$ratings $DB_site->query("SELECT * FROM " TABLE_PREFIX "articlerating WHERE articleid=$articleid");
    
$ratingcount $DB_site->num_rows($ratings);
    while (
$rating $DB_site->fetch_array($ratings))
    {
        
$totalrating $totalrating $rating['rating'];
    }
    
    if (
$ratingcount 0)
    {
        
$totalrating $totalrating/$ratingcount;
    }
    
    if (
$ratingcount == 0)
    {
        
$ratingstatus 'No Rating';
    }
    else
    {
        
$totalrating round($totalrating);
        
$ratingstatus "<img src=\"./images/rating/rating_$totalrating.gif\" style=\"padding-top:4px;\" alt=\"Rating: $totalrating\" height=\"9\">";
    } 

for some reason its not always working... its echoing rating_10.gif for some reason... my home page is www.ex-zone.com, article modules is on the bottom, view source and see.

Dean C 12-29-2004 08:53 AM

Ok what exactly are you trying to do here :)?

cinq 12-29-2004 09:12 AM

Hmm seems fine ...
If it is showing rating_10.gif, means the averaged rating for that particular articleid = 10.

a suggestion u might want to try
PHP Code:

//Rating calculation
$ratings $DB_site->query("SELECT rating FROM " TABLE_PREFIX "articlerating WHERE articleid=$articleid");
    
$ratingcount $DB_site->num_rows($ratings);
    
$totalrating 0;
    
    while (
$rating $DB_site->fetch_array($ratings))
    {
          
$ratevalue $rating['rating'];
        
$totalrating $totalrating $ratevalue;
    }
    
    if (
$ratingcount == 0)
    {
        
$ratingstatus 'No Rating';
    }
    else
    {
            
$totalrating $totalrating/$ratingcount;
        
$totalrating round($totalrating);
        
$ratingstatus "<img src=\"./images/rating/rating_$totalrating.gif\" style=\"padding-top:4px;\" alt=\"Rating: $totalrating\" height=\"9\">";
    } 

Would help if you allowed guests to view your article section ..

Guy G 12-29-2004 10:53 AM

Quote:

Originally Posted by Dean C
Ok what exactly are you trying to do here :)?

im trying to show the newest article's rating on vBA home page.

thanks cinq, trying it now.

EDIT: Thanks m8! that did the trick!

cinq 12-29-2004 11:08 AM

:)
You might want to cater
Code:

<span class="smallfont">
for the case when there is No Rating.

Guy G 12-29-2004 11:35 AM

Excellent, thanks for all m8.


All times are GMT. The time now is 06:39 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01123 seconds
  • Memory Usage 1,737KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (6)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete