Dejo mi solucion al ejercicio 2 de la entrega CU00844B del curso de programación en PHP desde cero relativo a eliminación de datos desde base de datos:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta lang="es"/>
</head>
<body>
<?php
$connect = mysqli_connect ("sql302.byethost17.com", "b17_18051302", "****");
mysqli_select_db ( $connect,"b17_18051302_mibasededatos" );
$tilde = $connect->query ( "SET NAMES 'utf8'" );
function mostrarContenido($connect){
$result = mysqli_query ( $connect,"SELECT * FROM agenda3" );
$row = mysqli_fetch_array ( $result );
echo $row["nombre"];
while ($row !== NULL){
echo "Nombre: ".$row["nombre"]."</br>";
echo "Apellido: ".$row["apellidos"]."</br>";
echo "Edad: ".$row["edad"]."</br>";
echo "Altura: ".$row["altura"]."</br>";
echo "********************************</br>";
$row = mysqli_fetch_array ( $result );
}
mysqli_free_result ( $result );
}
function eliminarEdad($connect){
mysqli_query ( $connect,"DELETE FROM agenda3 WHERE edad >= 34" );
}
function insertarPersona($connect){
mysqli_query ( $connect,"INSERT INTO agenda3 VALUE('Gabriel','Simchuk','37 N°1009',2213145,29,1.79)" );
}
function eliminarTabla($connect){
mysqli_query ( $connect,"TRUNCATE TABLE agenda3" );
}
function agregar3Registros($connect){
mysqli_query ( $connect,"INSERT INTO agenda3 VALUE('Gabriel','Simchuk','37 N°1009',2213145,29,1.79)" );
mysqli_query ( $connect,"INSERT INTO agenda3 VALUE('Magdalena','Palomeque','37 N°1009',2213145,27,1.67)" );
mysqli_query ( $connect,"INSERT INTO agenda3 VALUE('chicho','coco','37 N°1009',2213145,21,1.20)" );
}
function eliminarConDelete($connection){
mysqli_query ( $connection,"DELETE FROM agenda3" );
}
echo "<p>Contenido Inicial</p>";
mostrarContenido ( $connect );
eliminarEdad ( $connect );
echo "<p>Contenido luego de eliminar los de edad >= 35 </p></br>";
mostrarContenido ( $connect );
insertarPersona($connect);
echo "<p>Contenido luego de ingresarme</p></br>";
mostrarContenido ( $connect );
eliminarTabla($connect);
echo "<p>Despues de truncarla</p></br>";
mostrarContenido ( $connect );
agregar3Registros($connect);
echo "<p>Despues de agregar 3 registros desde 0</p></br>";
mostrarContenido ( $connect );
eliminarconDelete($connect);
echo "<p>Despues de eliminar la tabla con delete</p></br>";
mostrarContenido ( $connect );
mysqli_close ( $connect );
?>
</body>
</html>