It happens that I have this code armed in a Dreamwever platform, I need to find a way for all the data generated automatically by the "rand" command to be added in the "Totals" box, for both variables, both for x and for and. but I have no idea how to do it
"<?php
if ( isset($_POST['calcular']) ) {
$numero = $_POST['numero'];
}else{
$numero = 0;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="200" border="1" align="center">
<tr>
<td colspan="2" align="center" bgcolor="#00FF66">REGRESION LINEAL </td>
</tr>
<tr>
<td width="50%" bgcolor="#666699"><div align="center">Numero</div></td>
<td width="50%" align="center" bgcolor="#669966"><input name="numero"
type="text" id="numero" value="<?php echo $numero ; ?>" size="10"
maxlength="10" /></td>
</tr>
<tr>
<td colspan="2" align="center" bgcolor="#99FF00"><input name="calcular" type="submit" id="calcular" value="CALCULAR" /></td>
</tr>
</table>
</form>
<br />
<br />
<?php
if (isset ($_POST['calcular'])){
**$sumax = 1;
$sumay =2 ;
$sumaxy = 3 ;
$sumaxx = 4** ; (aqui puse 1,2,3,4. porque no se como definir la sumatoria total y no sabia que mas poner para que no me diera error el codigo)
$b=(($numero*$sumaxy)-($sumax*$sumay))/(($numero*$sumaxx)-($sumax*$sumax));
$a= ($sumay-($b*$sumax))/$numero ;
?>
<table width="800" border="1" align="center">
<tr>
<td width="20%" align="center">Numero</td>
<td width="20%" align="center">X</td>
<td width="20%" align="center">Y</td>
<td width="20%" align="center">XY</td>
<td width="20%" align="center">X^2</td>
</tr>
<?php
for($n=1; $n<=$numero; $n++){
?>
<tr>
<td width="20%" align="center"><?php echo $n; ?></td>
<td align="center">
<?php
$x = rand(20,250);
echo $x ;
?> </td>
<td width="20%" align="center">
<?php
$y = rand(20,210);
echo $y ;
?> </td>
<td align="center"><?php echo $x * $y ; ?></td>
<td align="center"><?php echo $x * $x ; ?></td>
</tr>
<?php
}
?>
<tr>
<td align="center">Totales</td>
<td align="center"><?php echo $sumax ; ?></td>
<td align="center"><?php echo $sumay; ?></td>
<td align="center"><?php echo $sumaxy; ?></td>
<td align="center"><?php echo $sumaxx; ?></td>
</table>
<br />
<br />
<table width="400" border="1" align="center">
<tr>
<td width="50%" align="center">A</td>
<td width="50%" align="center"><?php echo $a ; ?></td>
</tr>
<tr>
<td width="50%" align="center">B</td>
<td align="center"><?php echo $b ; ?></td>
</tr>
</table>
<?php
}
?>
<p> </p>
</body>
</html>