Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Curso de PHP y MySql [22.- Switch case]
Video: https://youtu.be/crnD48LUjyE
- Loading branch information
1 parent
49ac2b1
commit 81428ac
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Tutotial Switch</title> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<form> | ||
<div class="form-group"> | ||
<label>Selecciona un numero</label> | ||
<select class="form-control" name="numero"> | ||
<option>Selecciona un numero</option> | ||
<option>1</option> | ||
<option>2</option> | ||
<option>3</option> | ||
<option>4</option> | ||
<option>5</option> | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<button type="submit" class="btn btn-primary" name="enviar" value="enviar">Enviar</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<?php opcion(); ?> | ||
</div> | ||
</div> | ||
</body> | ||
|
||
</html> | ||
<?php | ||
function opcion() | ||
{ | ||
if (isset($_GET['enviar'])) { | ||
$numero = $_GET['numero'] ?? 0; | ||
switch ($numero) { | ||
case 1: | ||
echo "El numero seleccionado fue el 1"; | ||
break; | ||
case 2: | ||
echo "El numero seleccionado fue el 2"; | ||
break; | ||
case 3: | ||
echo "El numero seleccionado fue el 3"; | ||
break; | ||
case 4: | ||
echo "El numero seleccionado fue el 4"; | ||
break; | ||
case 5: | ||
echo "El numero seleccionado fue el 5"; | ||
break; | ||
default: | ||
echo "Humano debiste seleccionar un numero"; | ||
break; | ||
} | ||
} | ||
} | ||
?> |