下载了一个早期的投票系统,想实现一个用户每个作品都可以投票,但只能投一票!
麻烦高手进来修改以下代码?从数据库cdb_plusin_dfvote_tp中查询是否同一个ID的作品有同一个用户投票!下面的代码不能实现此功能!麻烦高手指导!- //===检查是否投过票
- $sql ="SELECT uname FROM cdb_plusin_dfvote_tp where id=".$id;
- $query = $db->query($sql);
- $total=mysql_result($query,0,"uname");
- if ($total==$discuz_uname)
- {
- showmessage($ts[self], './plugin.php?identifier=df_94vipcn_vote&module=dfvote');
- exit();
- }
-
- //===检查当前会员投票数量
-
- $sql ="SELECT * FROM cdb_plusin_dfvote_tp where uname='".$discuz_userss."'";
- $query = $db->query($sql);
- $total=$db->num_rows($query);//mysql_num_rows($query);
- if ($total>=$_DPLUGIN['df_94vipcn_vote']["vars"]["tpc"])
- {
- showmessage($ts[full], './plugin.php?identifier=df_94vipcn_vote&module=dfvote');
- exit();
- }
-
- //===处理投票成功
- $sql ="update cdb_plusin_dfvote_xs set p=p+1 where id=".$id;
- if ($db->query($sql)) //票数累加成功
- {
- $sql="insert into cdb_plusin_dfvote_tp(uname,tid,ip) values('".$discuz_userss."',".$id.",'".$ip."')";
- if ($db->query($sql)) //投票记录成功
- {
- $tpok1=$ts[tpok];
-
- //==如果随机奖励设置为开,则进行随机奖励
- Function getRandNumber($fMin, $fMax)
- {
- srand((double)microtime()*1000000);
- $fLen = "%0".strlen($fMax)."d";
- Return sprintf($fLen, rand($fMin,$fMax));
- }
- if ($_DPLUGIN['df_94vipcn_vote']["vars"]["tpjl"]==1)
- {
- $tpjl=getRandNumber(1,5);
- $sql="update cdb_members set extcredits2=extcredits2 +".$tpjl." where uid=". $discuz_uid ;
- $db->query($sql);
- $tpok1=$tpok1.",恭喜您!同时您获得了".$tpjl."的随机金钱奖励!";
- }
-
- //======================================
-
- showmessage($tpok1, './plugin.php?identifier=df_94vipcn_vote&module=dfvote');
- exit();
- }
- else //投票记录失败的话 就把票数再减去
- {
- $sql ="update cdb_plusin_dfvote_xs set p=p-1 where id=".$id;
- $db->query($sql);
-
- showmessage($ts[tpe1], './plugin.php?identifier=df_94vipcn_vote&module=dfvote');
- exit();
- }
- }
- else
- {
- showmessage($ts[tpe2], './plugin.php?identifier=df_94vipcn_vote&module=dfvote');
- exit();
- }
- }
复制代码 |