MOODLE(PHP)测验模板仅提供部分输出

时间:2018-01-10 13:13:34

标签: php mysql mysqli moodle

我有一个测验问题模板,我试图从MySQL表构建:

MYSQL TABLE:

CREATE TABLE `testbank` (
  `line` varchar(25) DEFAULT NULL,
  `process` varchar(250) DEFAULT NULL,
  `question` varchar(500) DEFAULT NULL,
  `reference` varchar(500) DEFAULT NULL,
  `ans1` varchar(250) DEFAULT NULL,
  `ans2` varchar(250) DEFAULT NULL,
  `ans3` varchar(250) DEFAULT NULL,
  `ans4` varchar(250) DEFAULT NULL,
  `correct` varchar(5) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

示例数据:

INSERT INTO `testbank` (`line`, `process`, `question`, `reference`, `ans1`, `ans2`, `ans3`, `ans4`, `correct`) VALUES
('246.80','COLOR OF MONEY','What is your favorite color for monetary denominations?','The U.S. Mint','Blue','Green','Grey','Brown','B');

PHP代码:

<?php

session_start();
include("connectw.php");

$z = 1;

echo '<?xml version="1.0 encoding="utf-8"?>' . PHP_EOL;
echo '<quiz>' . "\r\n" . "\r\n";

$result = mysql_query("SELECT line, process, question, reference, ans1, ans2, ans3, ans4, TRIM(TRAILING '\r' FROM correct) AS correct FROM testbank");

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

echo '<!-- question: ' . $z . ' -->' . "\r\n";
echo '<question type="mutlichoice">' . "\r\n";
echo '   <name>' . "\r\n";
echo '      <text>' . $row['line'] . ' ' . $row['process'] . '</text>' . "\r\n";
echo '   </name>' . "\r\n";
echo '   <questiontext format="html">' . "\r\n";
echo '   <text>' . "\r\n";
echo "      <![CDATA[(" . $row['line'] . " " . $row['process'] . ") " . $row['question'] . " <!-- " . $row['reference'] . " -->]]>" . "\r\n";
echo '   </text>' . "\r\n";
echo '   </questiontext>' . "\r\n";

echo '   <defaultgrade>1</defaultgrade>' . "\r\n";
echo '   <penalty>0.1</penalty>' . "\r\n";
echo '   <hidden>0</hidden>' . "\r\n";
echo '   <shuffleanswers>0</shuffleanswers>' . "\r\n";
echo '   <answernumbering>none</answernumbering>' . "\r\n";

        if ($row['correct'] == 'A') {$af1 = '100'; } else {$af1 = '0'; }
        if ($row['correct'] == 'B') {$af2 = '100'; } else {$af2 = '0'; }
        if ($row['correct'] == 'C') {$af3 = '100'; } else {$af3 = '0'; }
        if ($row['correct'] == 'D') {$af4 = '100'; } else {$af4 = '0'; }

echo '   <answer fraction="' . $af1 . '">' . "\r\n";
echo '      <text>' . $row['ans1'] . '</text>' . "\r\n";
echo '   </answer>' . "\r\n";
echo '   <answer fraction="' . $af2 . '">' . "\r\n";
echo '      <text>' . $row['ans2'] . '</text>' . "\r\n";
echo '   </answer>' . "\r\n";

if ($row['ans1'] == 'TRUE') {echo ''; } else {
echo '   <answer fraction="' . $af3 . '">' . "\r\n";
echo '      <text>' . $row['ans3'] . '</text>' . "\r\n";
echo '   </answer>' . "\r\n";
echo '   <answer fraction="' . $af4 . '">' . "\r\n";
echo '      <text>' . $row['ans4'] . '</text>' . "\r\n";
echo '   </answer>' . "\r\n";

}

$z = $z + 1;
echo '</question>' . "\r\n";
echo "\r\n";

}
echo '</quiz>' . "\r\n";

?>

问题:

虽然我有大约9,000个问题,但我只得到4条记录的输出(并且它开始了第5个问题)。

我有其他代码执行类似的事情,这些工作正常。我不明白我做错了什么。

我注意到的一件事是,当我减少每个项目之前的空格数echo'd [例如:echo ' <name>'echo ' <name>']时,它允许更多字符...几乎就像只向我显示有限数量的角色。

除了使用mysql_querymysqli_query之外,还有人看到任何需要改变的内容吗?

0 个答案:

没有答案