dongmao3131 2016-04-14 02:52
浏览 140

我如何从循环到数组中获取值传递给另一个php页面

i want to pass values from my loop to another PHP page. but it only pass the latest value. i tried to use array but it does not work.

     $equation_x0 = equation ($x0);
$equation_x1 = equation ($x1);

$k=1;


echo '<table colspan = "2" align = "center">';
echo '<tr><th style="width:350px;height:50px">ITERATIONS</th>';
echo '<th style="width:350px;">X</th></tr>';
echo '</table>';

do {


if (abs ($equation_x1-$equation_x0) < $delta) {

echo ' Solution cannot be found. ' . '<br>';
return 0;

}

$dx = ($x0*$equation_x1) - ($x1*$equation_x0);
$d = $equation_x1 - $equation_x0;
$x2 = number_format($dx / $d,5);
$equation_x2 = equation($x2);
$equation_x0 = $equation_x1;
$equation_x1 = $equation_x2;
$x0 = $x1;
$x1 = $x2;

echo '<table colspan = "2" align = "center">';
echo '<tr><td style="width:350px;height:50px" align = "center">' . $k . '</td>';
echo '<td style = "width:350px" align = "center">' . $x2 . '</td></tr>';
echo '</table>';

if ($k == $max_iter) {

break;

}

$k++;

} while (abs($equation_x2) > $delta && $k < $max_iter);

$_SESSION['k'] = $k;
echo $x2;


echo '<h1 align = "center" style = "color:red"><br>The required solution  is ' . $x2 . '</h1>' ;


$result = mysqli_query($connect, "SELECT * FROM project ORDER BY id DESC LIMIT 1 ");
$row = mysqli_fetch_assoc($result);

$id='id';
echo $equation;
echo '<br>' . $row['id'];

echo '<br><a href="plotsecant.php?id=' . $row['id'] . ' " >PLOT</a>';

echo '</figure>';

echo '</div>';
}

?>

i only echoed the last value of the $x2 but i want to pass all the value of $x2 to another PHP page for another purpose. is there a way?

// i found the solution for the array things but now i have problem to print out the array items in another php page. i keep getting (Notice: Array to string conversion)

i fix the earlier code

$roots = array();

do {

if (abs ($equation_x1-$equation_x0) < $delta) {

echo ' Solution cannot be found. ' . '<br>';
return 0;

}

$dx = ($x0*$equation_x1) - ($x1*$equation_x0);
$d = $equation_x1 - $equation_x0;
$x2 = number_format($dx / $d,6);
$equation_x2 = equation($x2);
$equation_x0 = $equation_x1;
$equation_x1 = $equation_x2;
$x0 = $x1;
$x1 = $x2;

echo '<table colspan = "2" align = "center">';
echo '<tr><td style="width:350px;height:50px" align = "center">' . $k . '</td>';
echo '<td style = "width:350px" align = "center">' . $x2 . '</td></tr>';
echo '</table>';

if ($k == $max_iter) {

break;

}

$k++;

$roots[]=$x2;

} while (abs($equation_x2) > $delta && $k < $max_iter);


for($i=0; $i<count($roots);$i++) {
$roots[$i] . '<br>';
}

$_SESSION['roots']= $roots;

this is my code to print out the array item.

$x2 = $_SESSION['roots'];

foreach($x2 as $roots) {
echo $roots . '<br>';
}

// i fix my code. it works already.

  • 写回答

1条回答 默认 最新

  • duanjiu4498 2016-04-14 02:59
    关注
    $x2 = number_format($dx / $d,5);
    

    There is not any syntax to change $x2 into an array.

    Try

    $x2 = isset($_SESSION['x2']) ? $_SESSION['x2']:[] ; 
    ... 
    $x2[] = number_format($dx / $d,5); 
    ... 
    $_SESSION['x2'] = $x2; 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)