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.