Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <?php
  2.  
  3. include("mysqli.inc.php");
  4.  
  5. $tabla='atletas';
  6.  
  7. $sentenciaMYSQL="SELECT nombre, sexo FROM $tabla";
  8.  
  9. $conexion=@mysqli_connect ($cfg_servidor,$cfg_usuario,$cfg_password,$cfg_basephp1);
  10. if(!mysqli_connect_errno()==0){
  11. print "<br>No ha podido realizarse la conexión mediante procesos<br>";
  12. print "Error número: ". mysqli_connect_errno()." equivalente a: ". mysqli_connect_error();
  13. exit();
  14. }
  15.  
  16. if($resultado=mysqli_query($conexion,$sentenciaMYSQL)){
  17. if(mysqli_affected_rows($conexion)>0){
  18. $i = 0;
  19. $j = 0;
  20. while ($registro = mysqli_fetch_row($resultado)){
  21.  
  22. //Guardar hombres y mujeres
  23. if($registro[1] == 'H'){
  24. $hombres[$i] = $registro[0];
  25. $i++;
  26. }else if($registro[1] == 'M'){
  27. $mujeres[$j] = $registro[0];
  28. $j++;
  29. }
  30.  
  31. }
  32. //Mostrar hombres
  33. echo "Hombres: ";
  34. foreach($hombres as $valor){
  35. echo $valor.", ";
  36. }
  37. //Mostrar mujeres
  38. echo "<br/> Mujeres: ";
  39. foreach($mujeres as $valor){
  40. echo $valor.", ";
  41. }
  42.  
  43. }else{
  44. print "La consulta no ha producido ningún resultado";
  45. exit;
  46. }
  47. }else{
  48. print "<br>No ha podido realizarse la consulta. Ha habido un error<br>";
  49. print "<i>Error:</i> ". mysqli_error($conexion)." <i>Código:</i> ".mysqli_errno($conexion) ;
  50. exit();
  51. }
  52.  
  53. mysqli_close($conexion);
  54.  
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement