<?php
/*Numeri interi*/
$int_col = $_POST['col']; //numero delle colonne
$int_row = $_POST['row']; //nomero delle righe
$int_col = (int)($int_col); //le colonne sono un numero intero
$int_row = (int)($int_row); //le righe sono un numero intero
/*Stringhe*/
$str_classallert = "class=input_allert"; //definisce l'errore del input
$str_allert = "<span class='allert'>Inserisci un numero!</span>"; //definisce il testo dell'errore
?>
<!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>
<title>Mappa Logica</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
.input_allert {
border : 3px solid red;
}
.allert {
font-size: 14px;
color: red;
}
.table {
border: 1px solid black;
width: 100%;
}
.tdgreen {
background-color: #009900;
height: 30px;
border: 1px solid black;
padding: 20px;
}
.tdgray {
height: 30px;
border: 1px solid black;
padding: 20px;
background-color: #999999;
}
.tdblack {
background-color: #000000;
height: 30px;
border: 1px solid black;
padding: 20px;
}
</style>
</head>
<body>
<h3 align="center">Mappa Logica - Esercizio n°2</h3>
<form action="mappa_logica.php" method="post">
Seleziona il numero di colonne:</p>
<input name="col" type="text" <? if ($int_col == 0) echo $str_classallert; ?> /> <?php if ($int_col == 0) echo $str_allert; ?>
Seleziona il numero di righe:</p>
<input name="row" type="text" <? if ($int_row == 0) echo $str_classallert; ?> /> <?php if ($int_row == 0) echo $str_allert; ?>
<input type="submit" value="Crea" />
</form>
<?php
if ($int_col != 0 && $int_row != 0) {
echo "<table class=table>";
for ($i=0; $i <= ($int_row - 1); $i++) {
echo "<tr>";
for ($j=0; $j <= ($int_col - 1); $j++) { //da qui non so più come procedere e quale ragionamento usare
echo "<td class=tdgreen> </td>";
}
echo "</tr>";
}
} else {
echo '';
}
?>
</body>
</html>