[Tableaux] rand pour un tableau
Bonjour,
j'essais de créer un tableau avec la taille demandé par l'utilisateur, ca c'est bon, puis de metre par randome la valeurs 'CO' dans certaines cases
J'utilise ce script, mais il me montre clairement que je ne modifie rien dans mon tableau... quelqu'un sais comment améliorer ce petit script?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| <html>
<head>
<?php
$nb_colonnes = $_POST['nb_colonnes'];
$nb_lignes = $_POST['nb_lignes'];
$nb_mines = $_POST['nb_mines'];
?>
<style type="text/css">
table,td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<div align="center">
<table id="grille" >
<?php
for ($x=1;$x<=$nb_lignes;$x++)
{
echo "<tr>";
for ($y=1;$y<=$nb_colonnes;$y++)
{
$array[$x][$y] = 'CN';
$valeur = $array[$x][$y];
echo "<td><input type='button' value='".$array[$x][$y]."' id='$x$y' onClick='javascript:alert(\"$valeur\");'/></td>";
}
echo "</tr>";
}
for ($i=0;$i<=$nb_mines;$i++){
$x = rand( 0, $nb_lignes );
$y = rand (0 , $nb_colonnes );
$array[$x][$y] = 'CO';
echo $x.$y;
echo "<script language='javascript'>document.getElementById('$x$y').value = 'CO';</script>";
}
?>
</table>
</div>
</body>
</html> |
la premiere page étant consitué d'un bloc html simple :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <html>
<body><br/>
<div align="center">
<form name="create" method="post" action="make_tab.php">
Nb col
<input type="text" value="" name="nb_colonnes"/><br/><br/>
Nb ligne
<input type="text" value="" name="nb_lignes"/><br/><br/>
Nb mines
<input type="text" value="" name="nb_mines"/><br/><br/><br/>
<input type="submit" value="Envoyer" name="submit"/>
</form>
</div>
</body>
</html> |
Merci :)