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]

sabret00the 11-29-2003 11:14 AM

thanks assassin, you've been a great help, i've got to final stages of this end of things, which means it'll be fully usable soon, all bar one thing, in my script, i'm processing the ratings via
PHP Code:

 if (isset'confess_rate' && $rate && $confessionid != '' && $bbuserinfo[userid] > 0) {

  
$flood $DB_site->query("SELECT timestamp FROM confessions ORDER BY timestamp DESC LIMIT 1");
  
$check $DB_site->fetch_array($flood);

  if ((
time() - $check[timestamp]) <= 10) {
   eval(
"standarderror(\"".gettemplate("confession_error_vote")."\");");
 }
  if (
$bbuserinfo[userid] == $DB_site->query("SELECT userid FROM confession_rate WHERE confessionid = $confessionid")) {
    eval(
"standarderror(\"".gettemplate("confession_error_novotetwice")."\");");
  } else {
   
$DB_site->query("INSERT INTO confession_rate SET
   confessionid = '
$confessionid',
   userid = '
$bbuserinfo[userid]',
   rate = '
$rate',
   timestamp = '"
.time ()."'");
  }
  
header("Location: $PHP_SELF?s=");
 } else {
  
header("Location: $PHP_SELF?s=");
 } 

but it won't submit to the database, what am i doing wrong?

assassingod 11-29-2003 11:18 AM

If you're implenting this into vB, you'd want to do something like:
PHP Code:

####### display form #######
if (!isset($_POST['process']) or $_POST['process'] == '')
{
//display vb and form stuff
}
 
// ###### start insert ######
if (isset($_POST['process']) and $_POST['process'] != '' and $_POST['process'] == 'go')
{
//vb stuff and insert into DB stuff


Not sure if that'll be a great deal of help, used it from my mailing list hack

sabret00the 11-29-2003 11:37 AM

sorry assassin, that was experimental code, heres what i was doing properly
PHP Code:

 case "voting":
// this conditional handles the rating
if ('confess_rate' && $rate && $confessionid != '' && $bbuserinfo[userid] > 0) {
$flood $DB_site->query("SELECT timestamp FROM confessions ORDER BY timestamp DESC LIMIT 1");
$check $DB_site->fetch_array($flood);
if ((
time() - $check[timestamp]) <= 10) {
eval(
"standarderror(\"".gettemplate("confession_error_vote")."\");");
}
if (
$bbuserinfo[userid] == $DB_site->query("SELECT userid FROM confession_rate WHERE confessionid = $confessionid")) {
    eval(
"standarderror(\"".gettemplate("confession_error_novotetwice")."\");");
} else {
$DB_site->query("INSERT INTO confession_rate SET
confessionid = '
$confessionid',
userid = '
$bbuserinfo[userid]',
rate = '
$rate',
timestamp = '"
.time ()."'");
}
header("Location: $PHP_SELF?s=");
} else {
header("Location: $PHP_SELF?s=");
}
    break; 

but i'll try the using the super globals :)

ps. this is just the form processing, the actual form display elsewhere in the document.

heres the link to where this is all happening http://www.ebslive.com/confessions/i...onfessionid=49

sabret00the 11-29-2003 01:32 PM

HTML Code:

<form method="post" name="confess_rate" action="?do=voting">
<input type="hidden" name="$confessionid">
<input type="hidden" name="$bbusername">
<table width="80%">
  <tr>
        <td align="center" colspan="2" nowrap>
          <smallfont>rate how good you think this confession is</smallfont><br />
          <input type="radio" name="rate" value="1" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="2" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="3" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="4" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="5" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="6" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="7" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="8" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="9" onclick="document.confess_rate.submit()">
          <input type="radio" name="rate" value="10"onclick="document.confess_rate.submit()">
        </td>
  </tr>
  <tr>
        <td align="left" width="50%"><smallfont>Saint</smallfont></td>
        <td align="right" width="50%"><smallfont>Sinner</smallfont></td>
  </tr>
  <tr>
        <td align="center" colspan="2"><br>
          <smallfont>this confession currently has a rating of $confession_avg_rate</smallfont>
        </td>
  </tr>
</table>
</form>

is the form that submits the data :)

sabret00the 11-29-2003 07:30 PM

lol, i was standing in the kebab shop when i finally got what you meant, thanks steven, took me all day but i got there in the end, gonna try it now :)

assassingod 11-29-2003 07:33 PM

Quote:

Originally Posted by sabret00the
lol, i was standing in the kebab shop when i finally got what you meant, thanks steven, took me all day but i got there in the end, gonna try it now :)

hehe, nothing like food the make you think:D

Hope it goes ok.

sabret00the 11-29-2003 10:17 PM

got the code down from 25 lines to 17 but it's still not working, i think this is down to the actual form rather than the coding tho.
PHP Code:

  // this conditional handles the rating
  
if ($_POST['submit'] == 'confess_rate') {
   
$confessionid intval($_POST['confessionid']);
   
$verify $DB_site->query_first("SELECT userid FROM confession_rate WHERE confessionid = $confessionid AND userid = $bbuserinfo[userid]");
   if (
$verify) {
    eval(
"standarderror(\"".gettemplate("confession_error_novotetwice")."\");");
   } else {
    
$DB_site->query("INSERT INTO confession_rate SET
    confessionid = '
$confessionid',
    userid = '
$bbuserinfo[userid]',
    rate = '
$rate',
    timestamp = '"
.time ()."'");
 
    
header("Location: $PHP_SELF?s="); //takes you back to main confession page
   
}
  } else {
   eval(
"standarderror(\"".gettemplate("confession_error_vote")."\");");
  } 


assassingod 11-29-2003 10:27 PM

*takes time away from his new hack*

Try using:
PHP Code:

if($action=="displayform")
{
// form code here
}
if (
$HTTP_POST_VARS['action']=="processform")
{
// queries and stuff


Then for the form tag, you would use something like
Code:

<form action="pagehere.php" method="post"><input type="hidden" name="s" value="$session[dbsessionhash]">
<!-- form code -->
 <input type="hidden" name="action" value="processform">
 <input type="submit" class="bginput" name="Submit" value="Submit Tutorial" accesskey="s">

</form>

You'll need to edit that a bit but thats a better way of doing from what i said earlier

Also, use the standardredirect function instead of header("locaion:");

sabret00the 11-30-2003 11:47 AM

i'm getting so close to giving up on this, i dunno what's wrong with it, i've tried so many methods, but it's not passing to the database, infact i get the error i set up to say the vote cannot be processed :(

PHP Code:

  if ($_POST['submit'] == "rate") {
   
$confessionid intval($_POST['confessionid']);
   
$verify $DB_site->query_first("SELECT userid FROM confession_rate WHERE confessionid = $confessionid AND userid = $bbuserinfo[userid]");
   if (
$verify) {
    eval(
"standarderror(\"".gettemplate("confession_error_novotetwice")."\");");
   } else {
    
$DB_site->query("INSERT INTO confession_rate SET
    confessionid = '
$confessionid',
    userid = '
$bbuserinfo[userid]',
    rate = '
$rate',
    timestamp = '"
.time ()."'");
 
    
header("Location: $PHP_SELF?s="); //takes you back to main confession page
   
}
  } else {
   eval(
"standarderror(\"".gettemplate("confession_error_vote")."\");");
  } 

arghhh, i think i just found it, i tried to pass the username with the form and not the userid :mad: will check it now :)

sabret00the 11-30-2003 12:00 PM

edit, it was such a stupid mistake
HTML Code:

<input type="hidden" name="$confessionid">
<input type="hidden" name="$bbusername">

should have been
HTML Code:

<input type="hidden" name="confessionid" value="$confessionid">
<input type="hidden" name="userid" value="$bbuserinfo[userid]">

:lol: it's still not working yet, but i'm a step closer :)

sabret00the 12-01-2003 12:00 AM

got it all working, special thanks to Kura, NTLDR, Assassingod, Mist and the many other who tried to help me. :)


All times are GMT. The time now is 01:04 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.01192 seconds
  • Memory Usage 1,842KB
  • 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
  • (2)bbcode_code_printable
  • (3)bbcode_html_printable
  • (8)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (21)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