Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("mysqli.inc.php");
- $tabla='atletas';
- $sentenciaMYSQL="SELECT nombre, sexo FROM $tabla";
- $conexion=@mysqli_connect ($cfg_servidor,$cfg_usuario,$cfg_password,$cfg_basephp1);
- if(!mysqli_connect_errno()==0){
- print "<br>No ha podido realizarse la conexión mediante procesos<br>";
- print "Error número: ". mysqli_connect_errno()." equivalente a: ". mysqli_connect_error();
- exit();
- }
- if($resultado=mysqli_query($conexion,$sentenciaMYSQL)){
- if(mysqli_affected_rows($conexion)>0){
- $i = 0;
- $j = 0;
- while ($registro = mysqli_fetch_row($resultado)){
- //Guardar hombres y mujeres
- if($registro[1] == 'H'){
- $hombres[$i] = $registro[0];
- $i++;
- }else if($registro[1] == 'M'){
- $mujeres[$j] = $registro[0];
- $j++;
- }
- }
- //Mostrar hombres
- echo "Hombres: ";
- foreach($hombres as $valor){
- echo $valor.", ";
- }
- //Mostrar mujeres
- echo "<br/> Mujeres: ";
- foreach($mujeres as $valor){
- echo $valor.", ";
- }
- }else{
- print "La consulta no ha producido ningún resultado";
- exit;
- }
- }else{
- print "<br>No ha podido realizarse la consulta. Ha habido un error<br>";
- print "<i>Error:</i> ". mysqli_error($conexion)." <i>Código:</i> ".mysqli_errno($conexion) ;
- exit();
- }
- mysqli_close($conexion);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement