Example #1
0
<?php

/**
 * Created by PhpStorm.
 * User: !ntruder
 * Date: 23-05-2015
 * Time: 12:12
 */
function unique_random($min, $max, $quantity)
{
    $numbers = range($min, $max);
    shuffle($numbers);
    return array_slice($numbers, 0, $quantity);
}
for ($i = 0; $i < 5; $i++) {
    $remain_sub_list = unique_random(0, 5, 2);
    print_r($remain_sub_list) . "<br>";
}
Example #2
0
function get_four_defs($connection, $correct_word, $num_headwords, $max_def_length = 256, $min_def_length = 0)
{
    $correct_def = get_def($connection, $correct_word);
    $correct_headword_id = $correct_word['headword_id'];
    $def1;
    $def2;
    $def3;
    //	$def_arr = array($correct_def);
    $pos = $correct_word['pos'];
    $regex_pos;
    if ($pos == 'sm' || $pos == 'sf' || $pos == 'smf') {
        $regex_pos = " AND pos REGEXP 'sm|sf'";
    } else {
        if ($pos == 'vt' || $pos == 'vi' || $pos == 'vp' || $pos == 'vti') {
            $regex_pos = " AND pos REGEXP 'v'";
        } else {
            if ($pos == 'adj') {
                $regex_pos = " AND pos REGEXP 'adj'";
            } else {
                $regex_pos = "";
            }
        }
    }
    $defs_query = "SELECT * FROM hms_defs \n" . "LEFT JOIN hms_headword ON headword_id=fk_defs_headword_id\n" . "WHERE CHAR_LENGTH(def) < {$max_def_length} AND CHAR_LENGTH(def) > {$min_def_length} {$regex_pos}";
    $defs_results = query_mysql($connection, $defs_query);
    $num_rows = mysqli_num_rows($defs_results);
    //$num_headwords in argument may not be necessary
    $random1 = unique_random($num_rows);
    $random2 = unique_random($num_rows, $random1);
    $random3 = unique_random($num_rows, $random1, $random2);
    mysqli_data_seek($defs_results, $random1);
    $row = mysqli_fetch_row($defs_results);
    $def1 = $row[2];
    //index 2 gets the definition
    $def1_headword_id = $row[1];
    //index 1 gets the headword_id
    mysqli_data_seek($defs_results, $random2);
    $row = mysqli_fetch_row($defs_results);
    $def2 = $row[2];
    $def2_headword_id = $row[1];
    mysqli_data_seek($defs_results, $random3);
    $row = mysqli_fetch_row($defs_results);
    $def3 = $row[2];
    $def3_headword_id = $row[1];
    $correct_def_str = $correct_def['def'];
    $headword = $correct_word['headword'];
    $pos = $correct_word['pos'];
    //	$def_arr = array("correct" => "$correct_def_str", "headword"=> $headword, "pos"=> $pos, "def1" => $def1, "def2" => $def2, "def3" => $def3);
    $def_arr = array("correct" => "{$correct_def_str}", "headword" => $headword, "pos" => $pos, "correct_headword_id" => $correct_headword_id, "def1" => $def1, "def2" => $def2, "def3" => $def3, "def1_headword_id" => "{$def1_headword_id}", "def2_headword_id" => "{$def2_headword_id}", "def3_headword_id" => "{$def3_headword_id}");
    //	print_r($def_arr);
    return $def_arr;
}
Example #3
0
     }
     if ($days == 2) {
         $table_day_wise_insert_query = "INSERT INTO wednesday VALUES(NULL,'{$year}',{$semester},'{$section}','{$table_row_wise['0']}','{$table_row_wise['1']}','{$table_row_wise['2']}','{$table_row_wise['3']}','{$table_row_wise['4']}','{$table_row_wise['5']}','{$table_row_wise['6']}','{$table_row_wise['7']}')";
         $table_day_wise_insert_result = mysql_query($table_day_wise_insert_query);
     }
     if ($days == 3) {
         $table_day_wise_insert_query = "INSERT INTO thursday VALUES(NULL,'{$year}',{$semester},'{$section}','{$table_row_wise['0']}','{$table_row_wise['1']}','{$table_row_wise['2']}','{$table_row_wise['3']}','{$table_row_wise['4']}','{$table_row_wise['5']}','{$table_row_wise['6']}','{$table_row_wise['7']}')";
         $table_day_wise_insert_result = mysql_query($table_day_wise_insert_query);
     }
     if ($days == 4) {
         $table_day_wise_insert_query = "INSERT INTO friday VALUES(NULL,'{$year}',{$semester},'{$section}','{$table_row_wise['0']}','{$table_row_wise['1']}','{$table_row_wise['2']}','{$table_row_wise['3']}','{$table_row_wise['4']}','{$table_row_wise['5']}','{$table_row_wise['6']}','{$table_row_wise['7']}')";
         $table_day_wise_insert_result = mysql_query($table_day_wise_insert_query);
     }
 }
 shuffle($lab_list);
 $days_random_choices = unique_random(0, 4, $lab_rows);
 $day_array = array("mondey", "tuesday", "wednesday", "thursday", "friday");
 $list_table_query = "SHOW TABLES";
 $list_table_result = mysql_query($list_table_query);
 for ($labs_count = 0; $labs_count < $lab_rows; $labs_count++) {
     $day_choice = $days_random_choices[$labs_count];
     $day_select = $day_array[$day_choice];
     $lecture_index_random_choice = array_rand($lab_slot_lecture);
     $lecture_slot_random_choice = $lab_slot_lecture[$lecture_index_random_choice];
     $lecture_slot_random_choice_next = $lecture_slot_random_choice + 1;
     $lab_name = $lab_list[$labs_count];
     $lab_allot_query = "UPDATE `tible`.`{$day_select}` SET `{$lecture_slot_random_choice}` = '{$lab_name}' WHERE `{$day_select}`.`year` = '{$year}' AND `{$day_select}`.`semester` = {$semester} AND `{$day_select}`.`section` = '{$section}'";
     $lab_allot_query1 = "UPDATE `tible`.`{$day_select}` SET `{$lecture_slot_random_choice_next}` = '{$lab_name}' WHERE `{$day_select}`.`year` = '{$year}' AND `{$day_select}`.`semester` = {$semester} AND `{$day_select}`.`section` = '{$section}'";
     //$lab_allot_query = "UPDATE $day_select SET $lecture_slot_random_choice = '$lab_name' WHERE year = '$year' AND semester = $semester AND section = '$section'";
     mysql_query($lab_allot_query) or die(mysql_error());
     mysql_query($lab_allot_query1);