FMyLife Type Moderate
Posted: Sat Oct 03, 2009 6:44 pm
Hi guys, I recently starting running this script, and it currently has moderate set up like this : Stories that are unactivated show up in the moderate box, and you can either click yes or no. If you click Yes, +1 vote is added to yes table in database, and same with no button. Then, afterwards, it picks a new story with a > ID # . I would like to change this so that the first story it picks up is random, so that everyone who keeps going back to this page will not keep moderating the same stories. It would also be preferable if they couldn't vote on the same story without refreshing the page. Can anyone help me out? I will include the code below.
<?php
include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];
$pid = intval($_REQUEST['pid']);
$i = intval($_REQUEST['i']);
if($pid > 0 && $i > 0)
{
if($i == "2")
{
// $addtosql = "AND A.PID>'$pid'";
}
elseif($i == "1")
{
$query="UPDATE posts SET active='0', vote_yes=vote_yes+1 WHERE PID='".mysql_real_escape_string($pid)."'";
$result=$conn->execute($query);
$query = "SELECT * FROM posts A, categories B WHERE A.category=B.CATID AND A.PID='".mysql_real_escape_string($pid)."'";
$executequery = $conn->execute($query);
$parray = $executequery->getarray();
$email = $parray[0][email];
$cat = $parray[0][category];
if ($email != "")
{
$catname = get_cat($cat);
$slink = $config['baseurl']."/view/".$catname."/".$pid;
$sendto = $email;
$sendername = $config['site_name'];
$from = $config['site_email'];
$subject = $lang['73'];
$sendmailbody= $lang['74']."<br>".$slink."<br><br>".$lang['75']."<br>".$sendername;
mailme($sendto,$sendername,$from,$subject,$sendmailbody,$bcc="");
}
}
elseif($i == "3")
{
// $query="DELETE FROM posts WHERE PID='".mysql_real_escape_string($pid)."' AND active='0'";
$query="UPDATE posts SET active='2', vote_no=vote_no+1 WHERE PID='".mysql_real_escape_string($pid)."'";
$result=$conn->execute($query);
}
}
$query = "SELECT * from posts A, categories B where A.category=B.CATID AND A.PID>'$pid' order by PID asc limit 1";
header("Content-Type: text/xml");
header("Expires: 0");
print "<root>";
$db=mysql_connect ($DBHOST,$DBUSER,$DBPASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($DBNAME);
$result = mysql_query($query) or die ('Query Error: ' . mysql_error());
while ($results = mysql_fetch_array($result))
{
print "<id>";
print $results[PID];
print "</id>\n";
print "<billet>";
print stripslashes($results[story]);
print "</billet>\n";
print "<date>";
print date("d/m/Y", $results[time]);
print " ";
print date("g:i a", $results[time]);
print " - ".$results[name];
print "</date>\n";
}
mysql_close();
print "</root>";
?>
Thank you !
<?php
include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];
$pid = intval($_REQUEST['pid']);
$i = intval($_REQUEST['i']);
if($pid > 0 && $i > 0)
{
if($i == "2")
{
// $addtosql = "AND A.PID>'$pid'";
}
elseif($i == "1")
{
$query="UPDATE posts SET active='0', vote_yes=vote_yes+1 WHERE PID='".mysql_real_escape_string($pid)."'";
$result=$conn->execute($query);
$query = "SELECT * FROM posts A, categories B WHERE A.category=B.CATID AND A.PID='".mysql_real_escape_string($pid)."'";
$executequery = $conn->execute($query);
$parray = $executequery->getarray();
$email = $parray[0][email];
$cat = $parray[0][category];
if ($email != "")
{
$catname = get_cat($cat);
$slink = $config['baseurl']."/view/".$catname."/".$pid;
$sendto = $email;
$sendername = $config['site_name'];
$from = $config['site_email'];
$subject = $lang['73'];
$sendmailbody= $lang['74']."<br>".$slink."<br><br>".$lang['75']."<br>".$sendername;
mailme($sendto,$sendername,$from,$subject,$sendmailbody,$bcc="");
}
}
elseif($i == "3")
{
// $query="DELETE FROM posts WHERE PID='".mysql_real_escape_string($pid)."' AND active='0'";
$query="UPDATE posts SET active='2', vote_no=vote_no+1 WHERE PID='".mysql_real_escape_string($pid)."'";
$result=$conn->execute($query);
}
}
$query = "SELECT * from posts A, categories B where A.category=B.CATID AND A.PID>'$pid' order by PID asc limit 1";
header("Content-Type: text/xml");
header("Expires: 0");
print "<root>";
$db=mysql_connect ($DBHOST,$DBUSER,$DBPASSWORD) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($DBNAME);
$result = mysql_query($query) or die ('Query Error: ' . mysql_error());
while ($results = mysql_fetch_array($result))
{
print "<id>";
print $results[PID];
print "</id>\n";
print "<billet>";
print stripslashes($results[story]);
print "</billet>\n";
print "<date>";
print date("d/m/Y", $results[time]);
print " ";
print date("g:i a", $results[time]);
print " - ".$results[name];
print "</date>\n";
}
mysql_close();
print "</root>";
?>
Thank you !