1

float値を持つ配列を渡すのに問題があります。他のファイルでは空です。これがコードです。助けてください...

 //file 1 
session_start();
//...
while ($row = pg_fetch_assoc($sql))
{       
    $notas[$i] = ($row['grade'] - 57.3)/12;                 
    $i++;
}

print("<FORM method=post action='../indicadores/distr_notas.php'>");
print("<input type=hidden name=notas value='$notas'>");
print("<INPUT type=submit>");
print("</FORM>");

//file 2
session_start();

$_SESSION['notas'] = $_POST['notas'];
$notas = $_SESSION['notas'];


$cant = count($notas);
echo $cant; 

まだ問題があります。POSTを間違って使用していると思います。私は3つのスクリプトを持っています。1つ目はエントリを取得し、2つ目は配列を取得し、3つ目はjpgraphを使用した配列のグラフを示しています。

file 1 // get the array
<?php  
    print("<FORM method=post action='proc_notas.php'>");
    print("Codigo de Carrera.<p>");
    print("<INPUT type=text name='cod_depto'><p>");
    print("<INPUT type=submit>");
    print("</FORM>");
 ?>


//file 2. 

if($_SERVER['REQUEST_METHOD'] != "POST")
{
print("<FORM method=post action='normal.php'>");
print("Desviación estándar.<p>");
print("<INPUT type=text name='desviacion'><p>");
print("<INPUT type=submit>");
print("</FORM>");
}
else
{
    $depto = $_REQUEST['cod_depto'];
    $ordenada = array();
    $z = array();
        $i = 0;
        $suma = 0;
    $conectar = new Conector();
    $cadena =  "select distinct a.grade FROM evaluation_student_evals a inner join td_estudiantes b on a.party_id = b.id_estudiante where b.cod_depto = '$depto' and a.grade >= 0 and a.grade <= 100 order by a.grade ";
    $sql = $conectar-> consultas($cadena);      
    //calcular sigma y miu      
    $total = pg_num_rows($sql);
    $sumanotas = new distribucion();
    $totalnotas = $sumanotas -> suma_notas($sql);
    $media = $totalnotas/$total;

//Normalizar datos de notas Z = (X-miu)/sigma
    while ($row = pg_fetch_assoc($sql))
    {       

        $ordenada[$i] = (1/(12*sqrt(pi())))*(exp(-0.5*(($row['grade']-$media)*($row['grade'] - $media))/($desviacion*$desviacion)));                                    
        $i++;   }               

    if (!isset($row))
    {
        header("Content-Type: text/html");
        print("<HTML><HEAD><TITLE>Desempeño de Aprendizaje</TITLE>");
        print("</HEAD>");
        print("<BODY>");
        print("$depto no se encuentra.");
        print("</BODY></HTML>");


//file 3 Graph the array
Here, I don´t know how to get the array $ordenada
4

4 に答える 4

0

ファイル3のjgraphに送信する前に、ファイル2のクエリ結果を計算したかったのですが、この部分が機能しない理由はまだわかりません。

//ファイル2

$depto = $_REQUEST['cod_depto'];
$desviacion = $_REQUEST['desviacion'];
$ordenada = array();
$i = 0;
$suma = 0;
$conectar = new Conector();
$cadena =  "select distinct a.grade FROM evaluation_student_evals a inner join td_estudiantes b on a.party_id = b.id_estudiante where b.cod_depto = '$depto' and a.grade >= 0 and a.grade <= 100 order by a.grade ";
$sql = $conectar-> consultas($cadena);      

//calcular sigma y miu          
$total = pg_num_rows($sql);
$sumanotas = new distribucion();
$totalnotas = $sumanotas -> suma_notas($sql);
$media = $totalnotas/$total;

//Normalizar datos de notas Z = (X-miu)/sigma
while ($row = pg_fetch_assoc($sql))
    {       
        $ordenada[$i] = (1/($desviacion*sqrt(pi())))*(exp(-0.5*(($row['grade']-$media)*($row['grade'] - $media))/($desviacion*$desviacion)));                                      $i++;
    }
$tmp= serialize($ordenada);
$tmp= urlencode($tmp);
echo "<form method=post action='../indicadores/distr_notas.php'>";
echo "<input type=hidden name=ordenada value=$tmp>";
echo "<input type=submit name=enviar>";
echo "</form>";

「calcularsigmaymui」の部分にコメントすることにしました。これで、配列をファイル3に渡すことができます。

//ファイル3

function array_recibe($url_array) {
    $tmp = stripslashes($url_array);
    $tmp = urldecode($tmp);
    $tmp = unserialize($tmp);

   return $tmp;
} 

$notas =$_REQUEST['ordenada'];
$notas =array_recibe($notas);

//jpgraph code
$graph = new Graph(600,400,"auto");
于 2011-05-30T17:32:16.653 に答える
0

これはボタン送信で機能します

 //file 1 
session_start();
//...
while ($row = pg_fetch_assoc($sql))
{       
    $notas[$i] = ($row['grade'] - 57.3)/12;                 
    $i++;
}

print("<FORM method=post action='../indicadores/distr_notas.php'>");
print("<input type=hidden name=notas value='".implode(',' $notas)."'>"); // use implode to convert array to string
print("<INPUT type=submit>");
print("</FORM>");

//file 2
session_start();

$notas = explode(',' $_POST['notas']);  // use explode to convert string to array

$cant = count($notas);
echo $cant;

そして、これはセッションで動作します

//file 1 
session_start();
//...
while ($row = pg_fetch_assoc($sql))
{       
    $_SESSION['notas'][$i] = ($row['grade'] - 57.3)/12;                 
    $i++;
}

print("<FORM method=post action='../indicadores/distr_notas.php'>");
print("<input type=hidden name=notas value='$notas'>");  // no need to use
print("<INPUT type=submit>");
print("</FORM>");

//file 2
session_start();

$notas = $_SESSION['notas'];


$cant = count($notas);
echo $cant;
于 2011-05-28T04:28:31.060 に答える
0
 $_SESSION['notas'][] = ($row['grade'] - 57.3)/12;     
于 2011-05-28T04:28:55.037 に答える
0

最初のファイルでは$notas配列を設定しますが、2 番目のファイルで$_POST['notas']はそれをセッション変数に追加してから に割り当て$notasます。2 番目のファイルのカウントは0です。これは、最初のファイルで生成された配列の要素をカウントするのではなく、POSTリクエストによって渡された ($_POST配列に格納された) 値のいずれかの要素をカウントするためです。

要約すると、1 つの配列を作成しますが、異なる one の要素をカウントします

2 番目のファイルを呼び出す方法 (別の要求ですか? 最初のファイルから含まれていますか?) に応じて、次のオプションがあります。

$notasA. (別のリクエストの場合)次のように変数をセッション配列要素に割り当てます。

// at the end of the first file:
$_SESSION['notas'] = $notas;

からではなく、それから読み取られた2番目のファイルで$_POST['notas']、または

B. (最初のファイルから 2 番目のファイルが含まれている場合) 最初のファイル ( $notas) と同じ変数名を使用し、代わりにそれを割り当て$_POST['notas']ます。

// in the second file, instead of " $_SESSION['notas'] = $_POST['notas']; "
$_SESSION['notas'] = $notas;
于 2011-05-28T04:34:40.933 に答える