значение_колонки function load_questions ($filename, $all_variant = 1) { $fl = @file ($filename); $fc = count ($fl); for ($qi = 1, $fi = 0; $fi < $fc; $qi++) { while (strlen(trim($fl[$fi])) == 0) $fi++; $quest [$qi]['id'] = NULL; $fl [$fi] = trim ($fl [$fi]); $pp = strpos ($fl [$fi], '. '); $quest [$qi]['num'] = 1 + substr ($fl [$fi], 0, $pp) - 1; $quest [$qi]['varid'] = $all_variant; $quest [$qi]['question'] = substr ($fl [$fi++], $pp+2); $quest [$qi]['rightanswer'] = 1; $quest [$qi]['answer1'] = trim ($fl [$fi++]); if ($quest [$qi]['answer1']{0} == '*') { $quest [$qi]['rightanswer'] = 1; $quest [$qi]['answer1'] = ltrim ($quest [$qi]['answer1'], "* \t"); } $quest [$qi]['answer2'] = trim ($fl [$fi++]); if ($quest [$qi]['answer2']{0} == '*') { $quest [$qi]['rightanswer'] = 2; $quest [$qi]['answer2'] = ltrim ($quest [$qi]['answer2'], "* \t"); } $quest [$qi]['answer3'] = trim ($fl [$fi++]); if ($quest [$qi]['answer3']{0} == '*') { $quest [$qi]['rightanswer'] = 3; $quest [$qi]['answer3'] = ltrim ($quest [$qi]['answer3'], "* \t"); } $quest [$qi]['answer4'] = trim ($fl [$fi++]); if ($quest [$qi]['answer4']{0} == '*') { $quest [$qi]['rightanswer'] = 4; $quest [$qi]['answer4'] = ltrim ($quest [$qi]['answer4'], "* \t"); } } return $quest; } // Загрузить ассоциативный массив $data в таблицу $table function load_into_database ($table, $data) { global $result, $QuestionsTable; foreach ($data as $datai => $cd) { $fields = array_keys ($cd); $sql = "INSERT INTO `$table` SET "; foreach ($fields as $cfi => $cf) { if (gettype($cd[$cf]) == 'integer') $sql .= "`$cf`=$cd[$cf]"; else if ($cd[$cf] == NULL) $sql .= "`$cf`=DEFAULT"; else { $ccc = mysql_escape_string ($cd[$cf]); $sql .= "`$cf`='$ccc'"; } if ($cfi < count ($fields)-1) $sql .= ', '; } $result = amysql_query ($sql); if (!$result) { echo mysql_error (); exit; return false; } } return true; } /* if (!isset ($req_file)) { echo 'Please call script as this: /load.php?file=FILE_WITH_QUESTIONS.TXT'; exit; } // Соединяемся с MySQL $link = mysql_connect ($dbhost, $dbuser, $dbpwd); if (!$link) { echo ('Could not connect to the database: ' . mysql_errno() . ": " . mysql_error()); exit; } if (!mysql_select_db($db)) { echo ('Could not select database.'); exit; } amysql_query ("SET NAMES cp1251"); //$result = amysql_query ("DROP TABLE IF EXISTS `$QuestionsTable`"); if (!$result) return false; //$result = amysql_query ("CREATE TABLE IF NOT EXISTS `$QuestionsTable` (`id` int(11) NOT NULL auto_increment, `varid` int(11) default NULL, `question` text NOT NULL, `answer1` text NOT NULL, `answer2` text NOT NULL, `answer3` text NOT NULL, `answer4` text NOT NULL, `rightanswer` int(11) default NULL, PRIMARY KEY `id` (`id`)) AUTO_INCREMENT=1"); if (!$result) return false; import_request_variables("gp", "req_"); if (load_into_database($QuestionsTable, load_questions($req_file))) echo 'Success'; else echo 'Error ' . mysql_errno() . ': ' . mysql_error(); // Очищаем MySQL-соединение @mysql_free_result($result); mysql_close($link); */ ?>