version 1.126, 2003/12/19 01:44:47
|
version 1.129, 2004/02/08 00:35:29
|
Line 746 sub makewhere {
|
Line 746 sub makewhere {
|
$type .= ($_=$TypeName{$_}) foreach @type; |
$type .= ($_=$TypeName{$_}) foreach @type; |
my $where=' 0 '; |
my $where=' 0 '; |
foreach (@type) { |
foreach (@type) { |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
$where.= " OR (Type ='$_') OR (Type ='$_Д') OR (Type ='Д$_') "; |
} |
} |
$where.= "OR (Type='ЧБ')" if ($type=~/Ч|Б/); |
$where.= "OR (Type='ЧБ')" if ($type=~/Ч|Б/); |
return $where; |
return $where; |
Line 974 sub PrintRandom {
|
Line 974 sub PrintRandom {
|
my %q; |
my %q; |
my $answer=$razd?0:1; |
my $answer=$razd?0:1; |
my @answers; |
my @answers; |
|
#my $t=time; |
my (@Questions) = &Get12Random($dbh, $type, $num); |
my (@Questions) = &Get12Random($dbh, $type, $num); |
my ($output, $i) = ('', 0); |
|
|
|
|
my ($output, $i) = ('', 0); |
|
#$output.="time=".(time-$t).p; |
if ($text) { |
if ($text) { |
$output .= " $num случайных вопросов.\n\n"; |
$output .= " $num случайных вопросов.\n\n"; |
} else { |
} else { |
Line 1062 sub PrintTournament {
|
Line 1064 sub PrintTournament {
|
my ($qnum1) = GetQNum($dbh,1); |
my ($qnum1) = GetQNum($dbh,1); |
$output .= h2("База вопросов"). |
$output .= h2("База вопросов"). |
h3("$qnum запис".&Suffix2($qnum). |
h3("$qnum запис".&Suffix2($qnum). |
" (не повторяется $qnum1)"); |
" (уникальных $qnum1)"); |
|
|
# h4("<table>". |
# h4("<table>". |
# Tr(td("Из них:"), td("Вопросов ЧГК: ".countz($dbh,'Ч'))). |
# Tr(td("Из них:"), td("Вопросов ЧГК: ".countz($dbh,'Ч'))). |
Line 1479 sub Get12Random {
|
Line 1481 sub Get12Random {
|
srand; |
srand; |
my $where=0; |
my $where=0; |
my $r=int (rand(10000)); |
my $r=int (rand(10000)); |
|
my $w1=$r<5000? "QuestionId<5000 ":"QuestionId>=5000"; |
|
$w1=1 if $type!~/Ч/; |
foreach (split '', $type) |
foreach (split '', $type) |
{ |
{ |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
Line 1489 sub Get12Random {
|
Line 1492 sub Get12Random {
|
# $q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
# $q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
# from Questions where $where order by val limit $num"; |
# from Questions where $where order by val limit $num"; |
# Когда на куличках появится mysql >=3.23 надо заменить на order by rand(); |
# Когда на куличках появится mysql >=3.23 надо заменить на order by rand(); |
$q="select QuestionId from Questions where $where order by rand() limit $num"; |
$q="select QuestionId from Questions where ($w1) AND ($where) order by rand() limit $num"; |
|
|
|
|
$sth=$dbh->prepare($q); |
$sth=$dbh->prepare($q); |