moodle(php)测试模板只提供部分输出

gpfsuwkq  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(332)

我有一个测验问题模板,我正试图从mysql表中构建它:
mysql表:

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";

?>

问题是:
虽然我有大约9000个问题,但我只得到了4条记录的输出(这是从第5个问题开始的)。
我还有其他代码可以做类似的事情,比如这个和那个工作得很好。我不明白我做错了什么。
我注意到的一件事是,当我在每个项目前减少空格的数量 echo'd [示例: echo ' <name>' 与。 echo ' <name>' ]它允许更多的字符。。。就像只给我看有限的几个字符。
除了使用 mysql_query 与。 mysqli_query ,有人看到什么需要改变的吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题