vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   vote/rate add-on query (https://vborg.vbsupport.ru/showthread.php?t=58867)

sabret00the 11-28-2003 09:39 AM

vote/rate add-on query
 
if i wanted to add a voting/rating process to something, how would i go about doing it?

i was thinking just set up an additional table
Code:

confession id | rate | voter (bbusername)
and then just join that to the other table via left joins?

sabret00the 11-28-2003 11:16 AM

lol, since this morning i've dummified, so how would i go about this after i set up the tables lol

Dean C 11-28-2003 03:22 PM

Moved to the correct forum :)

assassingod 11-28-2003 04:10 PM

You would do something like:
PHP Code:

$DB_site->query("UPDATE table SET rate = '$oldrate + 1', voter = '$bbuserinfo[username]'"); 

And use another query to get $oldrate

That's the way I did it for my vB3 point system (I think :dumbass: )

sabret00the 11-28-2003 04:41 PM

but wouldn't that just add or whatever to the rate was already there instead of working out an average rate?

assassingod 11-28-2003 04:44 PM

Quote:

Originally Posted by sabret00the
but wouldn't that just add or whatever to the rate was already there instead of working out an average rate?

You didn't say anything about working out the average rate, but to work out the average you would use
PHP Code:

$avgrate $DB_site->query("SELECT avg(rate) FROM table"); 


sabret00the 11-28-2003 05:23 PM

thanks i'll try implementing this code :)

sabret00the 11-28-2003 11:25 PM

ok in setting up the table would this be right?
[sql]CREATE TABLE confession_rate (
rateid MEDIUM INT UNSIGNED NOT NULL AUTO_INCREMENT,
confessionid BIGINT(20) ( SIGNED NOT NULL,
userid INT(10) SIGNED NOT NULL,
timestamp INT(11) NOT NULL,
rate SMALLINT(2) SIGNED NOT NULL,
PRIMARY KEY (rateid)
);[/sql]?
confessionid is set via php $confessionid
user_id is set by $bbuserinfo[userid]
timestamp is set when a confession is voted for
rate is what you're rating the confession (1-10)
and i set the primary key to by the confession id but that wouldn't work so i've decided i need another row for rateid.

sabret00the 11-29-2003 12:41 AM

figured out i don't need the left joins but would be great if you can tell me if i set that SIGNED and UNSIGNED stuff right.

assassingod 11-29-2003 07:31 AM

This would be a better table structure:
[SQL]
CREATE TABLE confession_rate (
rateid TINYINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
confessionid TINYINT(5) NOT NULL,
userid TINYINT(5) NOT NULL,
time TIMESTAMP(14) NOT NULL,
rate SMALLINT(5) NOT NULL,
PRIMARY KEY (rateid)
);
[/SQL]


All times are GMT. The time now is 10:14 PM.

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.01025 seconds
  • Memory Usage 1,738KB
  • 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)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete