to  ipman(ipman):
我试了,什么都不显示

解决方案 »

  1.   

    会不会和配置文件里的global_register有关啊?我是初学者,不过我觉得很有可能。
      

  2.   

    echo "<input type=radio name=$i  value=radiobutton>";把 name=$i 改一改.
    一个有效的变量名由字母或者下划线开头,后面跟上任意数量的字母,数字,或者下划线$nnrows['option_d'];数组键值最好加引号.$ans[$i];看了半天,不知道这是数组是从哪里来的!眼睛不好用了,唉
      

  3.   

    $ans[$i];这个数组是自己定义的,定义数组不需要声明啊
    还有,"<input type=radio name=$i  value=radiobutton>";那个变量是有效的
    因为我测试的时候,在原文件里直接输出$ans[$i];是可以输出来的,只是那个值传不到result.php里而已
      

  4.   

    name=$i;传过去之后的页面产生变量:$_POST['$i'] 和 $$i(当global_register=on时),后者是非法的.可是你没有传$ans[$i]啊.
    我没有找到类似 <input type="hidden" name=ans[<?=$i?>] value="<? echo $ans[$i]; ?>">的语句.
      

  5.   

    <input type="hidden" name="$total_num" value="<? echo $test_num; ?>">
    ?????
      

  6.   

    <input type="hidden" name="$total_num" value="<? echo $test_num; ?>">
    这是测试语句,我看看在别的页面能不能传值过去,输出$total_num
      

  7.   

    sophyia1223,
    你还在线吗?
    请把你的两个php文件完整的贴出来。这样对定位问题会有帮助。现在根据你的贴出的结果,你想在目标文件中显示 $ans[$i],
    可是你在第一个文件里根本就没有传输 $ans[$i] 。
      

  8.   

    start_chapter:<?
    require "config.php";
    require "global.php";
    global $connect,$single;if($check):check_test($ans,$test_num);
    exit;
    endif;$sql = "SELECT COUNT(*) AS coun FROM $single where tag=1 and chapter='$chapter' ORDER BY id DESC";
    $result = mysql_query($sql,$connect);
    $rows = mysql_fetch_array($result);
    $num = $rows[coun];
    $i=1;
    $test_num=10;
    $nsql = "SELECT *  FROM $single where tag=1 and chapter='$chapter' ORDER BY id DESC";
    $nresult = mysql_query($nsql,$connect);while($nrows = mysql_fetch_array($nresult))
    {
    $index[$i]=$nrows[id];
    $i++;
    }//$char[]  存1到NUM的随机数
    //$index[] 存符合要求的ID号码$i = 1;
    $randtest=randnum($num);
    $char[$i]=$randtest;
    while ($i<$test_num)


    $ttag=0;

    while($ttag==0)
    { $j = 1;
      $randtest=randnum($num);
      while($j<=$i)
      {
      if(strcmp($char[$j],$randtest)!=0)
      {
      $j++;
      }
      else
      break;
     
      }
      if($j>$i) 
      {
      $ttag=1;
      }
      }
      if($ttag==1)
      {
      $i++;
    $char[$i]= $randtest; 


    }
    }

    for($i=1;$i<=$test_num;$i++)
    {
    $idd[$i]=$index[$char[$i]];
    }
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <link href="../_notes/style.css" rel="stylesheet" type="text/css"></head><body background="../images/bg04.jpg">
    <table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
       <tr> 
      <td width=60% align=left>
      <font class=font12>题目总数:<? echo $test_num; ?>&nbsp;&nbsp;&nbsp;&nbsp;总分:100&nbsp;&nbsp;&nbsp;&nbsp;每题<? echo 100/$test_num; ?>分</font>
      </td>
      <td width=40% align=right>
      <font class=font12>剩余时间:<? echo "30"; ?>分钟</font>
      </td>
      </tr>
    </table><table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
     
      <tr>
        <td align=center>
            <form name=form1 method=post action=start_chapter.php target="frmdown">
        <table width="100%" border="0" align=center valign=middle cellpadding="0" cellspacing="1" bgcolor="#999999"><?
    for($i=1;$i<=$test_num;$i++)
    {
    $nnsql = "SELECT *  FROM $single where id=$idd[$i] ORDER BY id DESC";
    $nnresult = mysql_query($nnsql,$connect);
    $nnrows = mysql_fetch_array($nnresult);
    echo "<tr>";
    echo "<td height=35 valign=middle align=center width=4% bgcolor=#eeeeee>";
    echo "<font class=font12>";
    echo $i;
    echo "</font></td>";
    echo "<td height=35 width=36%   bgcolor=#eeeeee>";
    echo "<font class=font12>";
    echo $nnrows[theme];
    echo "</font></td>";
    echo "</font><td height=35 width=15%   bgcolor=#eeeeee>";
    echo "<font class=font12>";
    echo "<input type=radio name=$i  value=radiobutton>";
    echo $nnrows[option_a];
    echo "</font></td>";
    echo "<td height=35 width=15%   bgcolor=#eeeeee>";
    echo "<font class=font12>";
    echo "<input type=radio name=$i  value=radiobutton>";
    echo $nnrows[option_b];
    echo "</font></td>";
    echo "<td height=35 width=15%  bgcolor=#eeeeee>";
    echo "<font class=font12>";
    echo "<input type=radio name=$i  value=radiobutton>";
    echo $nnrows[option_c];
    echo "</font></td>";
    echo "<td height=35 width=15% valign=middle  bgcolor=#eeeeee>";
    echo "<font class=font12>";
    echo "<input type=radio name=$i  value=radiobutton>";
    echo $nnrows[option_d];
    echo "</font></td>";
    echo "</tr>";
    $ans[$i]=$nnrows[answer];
    }
    ?>
            </table>
            <input type="hidden" name="$total_num" value="<? echo $test_num; ?>">
            <input type="hidden" name=ans[<?=$i?>] value="<? echo $ans[$i]; ?>">
            <input name="check" type="submit" class="font12" value="交卷">
            <input name="reset" type="reset" class="font12" value="重做">
    <?
    check_test($ans,$test_num);
    ?>
            </form>
    </table><table width="95%"  border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
    <td height=122>
     <IFRAME frameBorder=0 id=frmdown name=frmdown 
          scrolling=auto src="result_show.htm" 
          style="HEIGHT: 122; VISIBILITY: inherit; WIDTH: 100%; Z-INDEX: 1"></IFRAME>
          </td>
          </tr>
    </table>
    </body>
    </html>
    result.php:<html>
    <head>
    <title>
    </title>
    <link href="../_notes/style.css" rel="stylesheet" type="text/css">
    </head>
    <body scroll=no style="MARGIN: 0px" background="../images/bg04.jpg">
    <table width="100%" border="0" align=center valign=middle cellpadding="0" cellspacing="0">
    <tr>
    <td>
    <table width="100%" border="0" align=center valign=middle cellpadding="0" cellspacing="1" bgcolor="#999999">
     <tr>
     <td width=10% align=center bgcolor=#eeeeee>
     <font class=font12>您的得分:</font>
    </td>
    <td width=90% bgcolor=#eeeeee><?
    echo "<font class=red12 >";
    echo "&nbsp;&nbsp;";
    echo "80";
    echo "</font>";
    ?></td>
    </tr>
     <tr>
     <td height="30" width=10% bgcolor=#eeeeee align="center">
     <font class=font12>标准答案:</font>
     </td>
     <td width=90% bgcolor=#eeeeee>
     <?
     echo "<table width=100% border=0 cellpadding=0 cellspacing=0>";
     echo "<tr>";
    for($i=1;$i<=10;$i++)
    {
    echo "<td align=center width=9% bgcolor=#eeeeee>";
    echo $ans[$i];
    echo "&nbsp;|&nbsp;";
    echo "</td>";
    }
    echo "</tr>";
    echo "</table>";
    ?>
    </td>
    </tr>
    <tr>
    <td height="30" width=10% bgcolor=#eeeeee align="center">
     <font class=font12>您的答案:</font>
     </td>
     <td width=90% bgcolor=#eeeeee> 
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align=center>
    <form name=form1 method=post action=index.php target="frmright">
    <input name="Submit" type="submit" class="font12" value="继续测试">
    </form>
    </td>
    </tr>
    </table></body>
    </html>
    后来我自己也测试了,确实值没有传出来,但是我不知道应该怎么解决,我想一点“交卷”后,响应,然后上面输出试题不变,下面就输出上面刚才所选的答案以及存在试题库中正确的答案。也就是$ans[$i]的值。
      

  9.   

    下载 PHP Manual,做如下阅读:英文版(推荐) <http://weblabor.hu/php-doc-chm/php_manual_sample_11.zip>
    Step 1.
    Getting Started -> A simple tutorial -> Dealing with FormsStep 2. 
    Language Reference -> Variables -> Variables from outside PHP (all)或者中文版 <http://www.php.net/distributions/manual/php_manual_zh.chm>
    第一步:
    入门指引 -> 简明教程 -> 处理表单第二步:
    语言参考 -> 变量 -> PHP 的外部变量(重点,详细阅读)
    总结几点对你的代码的建议。1。在文件 start_chapter.php 中的表单代码:
    <form name=form1 method=post action=start_chapter.php target="frmdown">
    处理表单的应为你的目标文件。2。在文件 start_chapter.php 中:
    <input type="hidden" name=ans[<?=$i?>] value="<? echo $ans[$i]; ?>">
    看来你是要利用表单进行数组的传递。
    PHP 利用 HTML 表单进行数据传递,一个 INPUT 项是不能进行数组的传递的。
    它根本不认识什么是数组。
    简单的解决办法是你写一个循环语句,生成多个 INPUT 项进行数组内每一个数据项的传递。
    反正 hidden 属性的 INPUT 用户也看不到。3。在目标文件 result.php 中:
    你直接使用了变量/数组 $ans[$i]。
    $ans 是 start_chapter.php 家的,result.php 根本还不认识这个变量/数组呀,你叫他
    怎么使用?
    解决办法很简单,只要花10分钟阅读一下开头列出的手册里的相关内容。Good luck!
      

  10.   

    抱歉,我误会你了。我收回第2个建议。
    第3个建议就是,在 result.php 中,利用 $_POST['$ans'] 的形式来接受并使用
    从 start_chapter.php 中传递过来的变量。
    见谅
      

  11.   

    <?php 
    //显示POST传来的数组
    echo "<pre>";
    print_r($_POST['me']);
    echo "</pre>";?>
    <form method=post action="">
    <?php
    for ($i = 0; $i < 10; $i++) {
    echo "<input type=text name='me[$i]' value='$i$i$i'>";
    //或者用: echo "<input type=text name='me[]' value='$i$i$i'>";};
    ?>
    <input type="submit">
    </form>