Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and lost your copy? Just file a support ticket through your "My Mods" page.


This forum is now closed and has moved to a new location! Click here to find out why.

AuthorTopic: Forum rating like/dislike  (Read 456 times)

iseeyou94056

  • Basic Member
  • *
  • Reputation Power: 1
  • iseeyou94056 has no influence.
  • Offline Offline
  • Posts: 2
    • View Profile
Forum rating like/dislike
« on: March 08, 2011, 11:24:55 AM »
one problem people can keep rating the same one over and over and people can rate there own topic if you know how to fix that please post the fix im just re learning to code so i forget how to do it



First add
ALTER TABLE `forum_topicsADD `ft_likeINT (11) DEFAULT 0
 
ALTER TABLE `forum_topicsADD `ft_dislikeINT (11) DEFAULT 0
ALTER TABLE `usersADD `fr_likeINT (11) DEFAULT 0
 
ALTER TABLE `usersADD `fr_dislikeINT (11) DEFAULT 0;

in your db in forum_topics
then open forums.php and scrool down to
function viewforum() 


and scrool down untill you see
$posts=number_format($r2['ft_posts']); 
print 
"<tr bgcolor='lightsteelblue'> <td align='center'>$pt<a href='forums.php?viewtopic={$r2['ft_id']}&lastpost=1'>{$r2['ft_name']}</a>$lt<br /> 
<small>{$r2['ft_desc']}</small></td>

after that add
<td align='center'><font color='green'>+{$r2['ft_like']}</font><br/><font color='red'>-{$r2['ft_dislike']}</font></td>
then go into
function viewtopic() 


and find
 
$qlink
="[<a href='forums.php?act=quote&viewtopic={$_GET['viewtopic']}&post={$r['fp_id']}'>Quote Post</a>]"

and under it add
 
$rlink
="[<a href='forum2.php?LID={$_GET['viewtopic']}'>Like</a>] 
[<a href='forum2.php?DID={$_GET['viewtopic']}'>Dislike</a>]"


then find
print "<tr bgcolor='steelblue'> 
<th align='center' width=20%>Post #{$no}</th> <th align='center'>Subject: {$r['fp_subject']}<br /> 
$t $qlink$slink$elink$dlink

after $dlink
add
$rlink
then make a file called forum2.php and put this inside it
 
<?php
$i
=('globals.php');
include 
"$i";
$_GET['LID'] = abs((int) $_GET['LID']);
$_GET['DID'] = abs((int) $_GET['DID']);
if(
$_GET['LID'])
{
global 
$ir$userid$h$db;
$p $db->query("SELECT ft_id, ft_name FROM forum_topics WHERE ft_id = ".$_GET['LID']);
$r $db->fetch_row($p);
if (
$r['ft_id'] == $ir['fr_like']) 
{echo 
"You already voted on this topic";}
else {
echo 
"You have liked the topic";
$db->query("UPDATE forum_topics SET ft_like=ft_like+1 WHERE ft_id={$r['ft_id']}");
$db->query("UPDATE users SET fr_like=concat('{$r['ft_id']}') WHERE userid=$userid");
}
}
else if(
$_GET['DID'])
{
global 
$ir$userid$h$db;
$p $db->query("SELECT ft_id, ft_name FROM forum_topics WHERE ft_id = ".$_GET['DID']);
$r $db->fetch_row($p);
if (
$r['ft_id'] == $ir['fr_dislike']) 
{echo 
"You already voted on this topic";}
else {
echo 
"You have disliked the topic";
$db->query("UPDATE forum_topics SET ft_dislike=ft_dislike+1 WHERE ft_id={$r['ft_id']}");
$db->query("UPDATE users SET fr_dislike=concat('{$r['ft_id']}') WHERE userid=$userid");
}
}
else
{
echo 
"Invalid use of file";
}
?>


and i am pretty sure thats it
if you know ways to make it better let me know
Logged
 


This forum is now closed and has moved to a new location! Click here to find out why.