Parašė Qrmiz· 2008 Sau. 2 18:01:05
#1
Sveiki,
yra tokia problemėlė, turiu anekdotų modą ir į jį bandau įdėti reitingavimą prie kiekvieno anekdoto, bet kai prabalsuoju už vieną anekdotą, reitingas užsideda visiems, kame čia bėda? (šiaip viskas veikia, tik su reitingavimu blogai) va kodas:
if (!isNum($cat_id)) { header("Location:".$PHP_SELF); exit; }
if ($data = dbarray(dbquery("SELECT * FROM ".$db_prefix."joken_cat WHERE joken_cat_id='$cat_id'"))) {
opentable($locale['EJN_400'].": ".$data['joken_cat_name']);
$rows = dbcount("(*)", "joken", "joken_cat='$cat_id'");
if (!$rowstart) $rowstart = 0;
if ($rows != 0) {
$result = dbquery("SELECT * FROM ".$db_prefix."joken WHERE joken_cat='$cat_id' ORDER BY joken_name LIMIT $rowstart,8");
$numrows = dbrows($result); $i = 1;
while ($data = dbarray($result)) {
if ($data['joken_datestamp']+604800 > time()+($settings['timeoffset']*3600)) {
$new = " <span class='small'>".$locale['EJN_410']."</span>";
} else {
$new = "";
}
echo "<table width='600' align='center' cellpadding='0' cellspacing='1' class='tbl-border'><tr><td class='tbl2'>";
/// 1
if (isset($_POST['rate'])) {
if (isNum($_POST['rating']) && !dbcount("(*)","joke_ratings","rate_user = '".$userdata['user_id']."' AND rate_subject = '".$data['joken_id']."'") && iMEMBER) {
$rezultatas = dbquery("INSERT INTO ".$db_prefix."joke_ratings (rate_user,rate_subject,rate_opt,rate_date,rate_ip) VALUES ('".$userdata['user_id']."','".$data['joken_id']."','".$_POST['rating']."','".time()."','".$_SERVER['REMOTE_ADDR']."');");
if ($rezultatas) redirect(BASEDIR."anekdotai.php?cat_id=$cat_id");
}
}
/// 2
if (iMEMBER) {
if (!dbcount("(*)","joke_ratings","rate_user = '".$userdata['user_id']."' AND rate_subject = '".$data['joken_id']."'")) {
echo " <form method='post' action='".BASEDIR."anekdotai.php?cat_id=$cat_id'>\n<select name='rating' class='textbox'>\n";
for ($i = 1; $i < 6; $i++) echo "<option value='$i'>$i</option>\n";
echo "</select> <input name='rate' type='submit' value='Vertinti' class='textbox'>\n</form>\n";
}
}
echo "<b>Pavadinimas:</b> ".$data['joken_name']." $new\n";
if (iADMIN) {
echo " <span class='small'>(<a href='".ADMIN."joken_admin.php?step=edit&joken_cat_id=$cat_id&joken_id=".$data['joken_id']."'>".$locale['EJN_2010']."</a>)</span>";
}/// 3
echo "<br><b>Reitingas:</b> ";
$v = 0;
$result2 = dbquery("SELECT * FROM ".$db_prefix."joke_ratings WHERE rate_subject = '".$data['joken_id']."'");
while ($datax = dbarray($result2)) $v = $v+$datax['rate_opt'];
$res = $v;
$vert = (dbrows($result2) != 0 ? round($res/dbrows($result2),2) : "");
$rdata = dbarray(dbquery("SELECT * FROM ".$db_prefix."joke_ratings WHERE rate_subject = '".$data['joken_id']."' ORDER BY rate_date DESC LIMIT 1"));
if ($vert < 1 ) {
echo "Nėra\n";
}
elseif ($vert == 1) {
echo "<img src='".IMAGES."star.png'>";
}
elseif ($vert > 1 AND $vert < 2) {
echo "<img src='".IMAGES."star.png'><img src='".IMAGES."starh.png'>";
}
elseif ($vert == 2) {
echo "<img src='".IMAGES."star.png'><img src='".IMAGES."star.png'>";
}
elseif ($vert > 2 AND $vert < 3) {
echo "<img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."starh.png'>";
}
elseif ($vert == "3") {
echo "<img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'>";
}
elseif ($vert > 3 AND $vert < 4) {
echo "<img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."starh.png'>";
}
elseif ($vert == "4") {
echo "<img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'>";
}
elseif ($vert > 4 AND $vert < 5) {
echo "<img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."starh.png'>";
}
elseif ($vert <= "5") {
echo "<img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'><img src='".IMAGES."star.png'>";
}
else {
echo "Reitingo nėra";
}
echo "</td><td class='tbl2' width='200'><b>".$locale['EJN_2003']."</b> <a href='".BASEDIR."~".$data['joken_nick']."'>".$data['joken_nick']."</a><br>
<b>E-Paštas:</b> <a href='mailto:".$data['joken_mail']."'>".$data['joken_mail']."</a><br>
<b>".$locale['EJN_411']."</b> ".showdate("%Y-%m-%d", $data['joken_datestamp'])."
</td></tr><tr><td class='tbl1' colspan='2'>";
if ($data['joken_description'] != "")
$joken_joken = $data['joken_description'];
$joken_joken = nl2br($joken_joken);
echo "<br>".$joken_joken."<br><br>\n";
echo "</td></tr></table>\n";
echo ($i != $numrows ? "<br>\n" : "\n"); $i++;
}
closetable();
echo " <a href=\"javascript:history.go(-1)\"><b>".$locale['EJN_2009']."</b></a><br><div align='center' style='margin-top:5px;'>\n".makePageNav($rowstart,8,$rows,3,"$PHP_SELF?cat_id=$cat_id&")."\n</div>\n";
} else {
echo "<center><br>".$locale['EJN_2004']." <a href='anekdotai_prideti.php'>".$locale['EJN_2005']."</a> (tik nariams)<br><br></center>\n";
closetable();
}