0

嗨,我得到了动态数组来获取一个表单,我还需要将该数组传递给其他表单。我还执行了一些计算,我在下面显示我需要传递$data_t1,因为它包含动态数组显示我可以传递为其他形式。

page1.php

    <?php

        for ($i = 1; $i <= $de; $i++) {
        ?>
        <tr>

            <td>
                <select id="in4-<?php echo $i; ?>" name="t1[<?php echo $i; ?>]" onclick="getText3(<?php echo $i; ?>)" onchange="getText39(<?php echo $i; ?>)" onmouseout="getText89(<?php echo $i; ?>)">
                    <option value="0">0</option>
                    <option value="12">12</option>
                    <option value="18">18</option>
                    <option value="24">24</option>
                    <option value="75">75</option>
                </select>
            </td>
            <td>
                <input type="text" name="t2[<?php echo $i; ?>]" id="in1-<?php echo $i; ?>" onblur="getText3(<?php echo $i; ?>)" onchange="getText39(<?php echo $i; ?>)" onmouseout="getText89(<?php echo $i; ?>)"/>
            </td>
            <td>
                <select name="a1[<?php echo $i; ?>]" id="in2-<?php echo $i; ?>" onclick="getText3(<?php echo $i; ?>)"onchange="getText39(<?php echo $i; ?>)" onmouseout="getText89(<?php echo $i; ?>)" >
                    <option value="0">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                </select>
            </td>
            <td>
                <input type="text" id="in3-<?php echo $i; ?>" name="username[<?php echo $i; ?>]" readonly="readonly" />
            </td>
<?php }?>
        </table>

    <input type="submit" name="submit" />



coding of acessing array from page1.php

<?php

if (isset($_POST['submit'])) {

    $data_t1 = $_POST['t1'];


    foreach ($data_t1 as $key => $value) {

        $value ;
       $_POST['t2'][$key];
    $_POST['a1'][$key];
      $_POST['username'][$key]; 



    }
      $data_t2 = $_POST['t2'];
      $data_t3=$_POST['a1'];
      $data_t4=$_POST['username'];

}

?>
  <?php
  //database connection
$db = new PDO("mysql:host=localhost;dbname=ems",'root','');
//query
$sql = "INSERT INTO table1 (c0,c1, c2, c3, c4 ,c13) VALUES ('',:c1, :c2, :c3, :c4, '$d')";
$stmt = $db->prepare($sql);
foreach ($data_t1 as $i => $value) {
    $stmt->execute(array(
       ':c1'=>$data_t1[$i],
       ':c2'=>$data_t2[$i],
       ':c3'=>$data_t3[$i],
       ':c4'=>$data_t4[$i],
    ));
} ?>
<?php
include('config.php');
$sa="select * from table1 where timestamp=now()";
$result=mysql_query($sa) or die(mysql_error());
$th=-2;
$xa=1;
$xb=2;
$xc=2;
echo "<table border='1'>
<tr>

</tr>";
$row_count=0;

while($row = mysql_fetch_array($result)) 
{ 
     $row['c1'];
   $row['c2'];
     $row['c3'];
     $row['c4'];

    $a[]=$row['c1'];
        $b[]=$row['c2'];
            $c[]=$row['c3'];
            $d[]=$row['c4'];

            //tube lights//
                $m[]=round(($row['c1']/$row['c4']),2);
                $n[]=round(($row['c2']/$row['c4']),2);
                $o[]=round(($row['c3']/$row['c4']),2);

                //ccr model technique//
                //tube lights//
                $m1[]=abs(round((((($row['c1'])*($th)+($row['c1']*$xa)+($row['c5']*$xb)+($row['c9']*$xc))+1)/2),2));
                $n1[]=abs(round((((($row['c2'])*($th)+($row['c2']*$xa)+($row['c6']*$xb)+($row['c10']*$xc))+1)/2),2));
                $o1[]=abs(round((((($row['c3'])*($th)+($row['c3']*$xa)+($row['c7']*$xb)+($row['c11']*$xc))+1)/2),2));



                $row_count++;

}

 //optimial values//
$fa=implode($a,',');
$fa1=explode(',',$fa);
$fb=implode($b,',');
$fb1=explode(',',$fb);
$fcc=implode($c,',');
$fcc1=explode(',',$fcc);
$fe=implode($e,',');
$fe1=explode(',',$fe);
$ff=implode($f,',');


    //for efficeiency frointer//

for($i=0;$i<$row_count;$i++) 
{ // do the exploding, the imploding, the row echoing for each row// 
echo "<table border='1' align='center'>
<tr>
<th>Inputs</th>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>";
echo "Measuring1".($i+1);
  echo "<tr>";
  //tube lights//
     $f=implode($m,',');
     $r=explode(',',$f);

     $f1=implode($n,',');
     $r1=explode(',',$f1);

     $f2=implode($o,',');
     $r2=explode(',',$f2);


echo "<td>" ."W"</td>";
echo "<td>".$r[$i]. "</td>";
echo "</tr>"; 
echo  "<td>" ."No. "</td>";
echo "<td>".$r1[$i]. "</td>";
;
 echo "</tr>"; 
echo  "<td>" ."Dur "."</td>";
echo "<td>".$r2[$i]. "</td>";
echo "</tr>"; 

echo  "</table>";
}
for($i=0;$i<$row_count;$i++) 
{
echo "<table border='1' align='center'>
<tr>
<th>Inputs</th>
<th>ccr</th>
<th>ccr</th>
<th>Ccr</th>
</tr>";
  echo "<tr>";
  echo "Measuring 2".($i+1);  
      //tube lights//
     $fc=implode($m1,',');
     $rc=explode(',',$fc);

     $fc1=implode($n1,',');
     $rc1=explode(',',$fc1);

     $fc2=implode($o1,',');
     $rc2=explode(',',$fc2);

     //ccr model technique// 
 echo "<td>" ."Wa ". "</td>";
echo "<td>".$rc[$i]. "</td>";
echo "</tr>"; 
echo  "<td>" ."n ". "</td>";
echo "<td>".$rc1[$i]. "</td>";
echo "</tr>"; 
echo  "<td>" ."Dur "."</td>";
echo "<td>".$rc2[$i]. "</td>";
echo  "</table>";
}
?>

<?php
for($i=0;$i<$row_count;$i++) 
{
echo "<table border='1' align='center'>
<tr>
<th>Inputs</th>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>";
 echo "<tr>";
  echo " Optimial values Of Room ".($i+1);
  //voltage of appliances//
   echo "<td>" ."W". "</td>";
if($fa1<=$rc)
{

echo "<td>". $fa1[$i]."</td>";
}
else
{

echo "<td>". $rc[$i]."</td>";
}
  echo "<tr>";
      echo "<td>" ."Du". "</td>";
if($fcc1<=$rc2)
{
echo "<td>". $fcc1[$i]. "</td>";
}
else
{
echo "<td>". $rc2[$i]. "</td>";
}
echo "</tr>";
 echo "<tr>";
    echo "<td>" ."Co". "</td>";
if($fa1<=$rc && $fb1<=$rc1 && $fcc1<=$rc2 )
{

 $gk[]=round(((($fa1[$i]*$fb1[$i]*$fcc1[$i])*30)/1000),2);
 echo  "<td>" . $gk[$i]. "</td>";
 }
else
{
$gk1[]=round(((($rc[$i]*$rc1[$i]*$rc2[$i])*30)/1000),2);
 echo  "<td>" . $gk1[$i]. "</td>";
}

?>

请帮帮我。

4

2 回答 2

2

我想评论@mightyuhu 之前的回答,但我还没有代表,所以我会这样尝试:

仅从阅读您的问题而不是完整的有点混乱的代码来看,我会说他的方法是完全正确的:会话。
但是由于您显然不知道如何处理它们-这里有一个非常简短的操作方法:

调用session_start();您想要访问共享数据的任何站点 - 但在进行任何输出之前调用它,在 php-tags 之外的任何回显或打印或空行或 html 代码之前调用它。之后,您可以通过$data = $_SESSION['my_variable_name'];和访问/设置/修改您的会话数据$_SESSION['my_variable_name'] = $new_data;
如果您想在之后删除数据,请致电unset($_SESSION['my_variable_name']);.

希望有帮助:)

于 2013-06-01T11:12:19.903 回答
1

看一下SESSIONs,您可以在其中存储临时会话数据。

于 2013-06-01T10:54:21.683 回答