RANKING

[insert_php]

require_once(“../include/test4.php”);
mysqli_query($cxn,”SET NAMES ‘utf8′”);

$query0a = “SELECT statistic_ref_id FROM uipn_wp_pro_quiz_statistic_ref”;
$result0a = mysqli_query($cxn,$query0a) or die (“Whoops 0a”);
$num0a=mysqli_num_rows($result0a);

$query0b = “SELECT SUM(notazok) AS num0b FROM ranking2”;
$result0b = mysqli_query($cxn,$query0b) or die (“Whoops 0b”);
$row0b = mysqli_fetch_assoc($result0b);
extract($row0b);

$num0a=$num0a*10;

if ($num0a!=$num0b)

{

//———————– UPDATE tabuliek RANKING a RANKING2 —————————

$delete=”TRUNCATE TABLE ranking”;
mysqli_query($cxn,$delete);

$query0 = “SELECT id,user_nicename FROM uipn_users”;
$result0 = mysqli_query($cxn,$query0) or die (“Whoops 0”);

while ($row0 = mysqli_fetch_assoc($result0))
{
extract($row0);

$query1 = “SELECT
SUM(uipn_wp_pro_quiz_statistic.correct_count) AS cc,
SUM(uipn_wp_pro_quiz_statistic.incorrect_count) AS ic,
SUM(uipn_wp_pro_quiz_statistic.points) AS points,
COUNT(uipn_wp_pro_quiz_statistic_ref.statistic_ref_id) AS notazok
FROM uipn_wp_pro_quiz_statistic
JOIN uipn_wp_pro_quiz_statistic_ref ON uipn_wp_pro_quiz_statistic.statistic_ref_id=uipn_wp_pro_quiz_statistic_ref.statistic_ref_id
WHERE uipn_wp_pro_quiz_statistic_ref.user_id =$id”;

$result1 = mysqli_query($cxn,$query1) or die (“Whoops 1”);
$row1 = mysqli_fetch_assoc($result1);
extract($row1);

if ($notazok!=0)
{
$i=$i+1;
$ntest=round($notazok/10,2);
$nfaktor=round($ntest/($ntest+1),2);
$percent=round($cc/$notazok*100,2);
$ppq=round($points/$notazok,2);
$ppcq=round($points/$cc,2);
$score=round($percent*$ppq*$nfaktor,2);

$query2 = “INSERT INTO ranking (id,user,notazok,spravne,nespravne,body,percenta,ppq,ppcq,skore1) VALUES (‘$id’, ‘$user_nicename’, ‘$notazok’, ‘$cc’,’$ic’, ‘$points’, ‘$percent’, ‘$ppq’, ‘$ppcq’, ‘$score’)”;
$result2 = mysqli_query($cxn,$query2) or die (“Whoops 2″);
}

}

$delete2=”TRUNCATE TABLE ranking2”;
mysqli_query($cxn,$delete2);

$query3 = “SELECT * FROM ranking ORDER BY skore1 DESC”;
$result3 = mysqli_query($cxn,$query3) or die (“Whoops 3”);

while ($row3 = mysqli_fetch_assoc($result3))
{
$j=$j+1;
extract($row3);

$query4 = “INSERT INTO ranking2 (id,user,notazok,spravne,nespravne,body,percenta,ppq,ppcq,skore1,poradie) VALUES (‘$id’, ‘$user’, ‘$notazok’, ‘$spravne’,’$nespravne’, ‘$body’, ‘$percenta’, ‘$ppq’, ‘$ppcq’, ‘$skore1′,’$j’)”;
$result4 = mysqli_query($cxn,$query4) or die (“Whoops 4”);

}

//———————————————————————————

}

// ———- Vypisanie RANKINGU ———————————————–

echo “

“;
echo “

“;

$query = “SELECT * FROM ranking2 ORDER BY poradie ASC”;
$result = mysqli_query($cxn,$query) or die (“Whoops “);

while ($row = mysqli_fetch_assoc($result))
{

extract($row);

$percenta=number_format($percenta,2);
$skore1=number_format($skore1,2);
echo “

“;

if ($poradie==200) {break;}

}

echo “

RANKMENO# ABS. OTÁZOKBODYÚSPEŠNOSŤAF-SKÓRE
$poradie.$user$notazok$spravne$nespravne$body$percenta %$skore1

“;
[/insert_php]

[Chcem si spustiť ďalší test…]