Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/05/2015, 09:48
acsdc_universal
 
Fecha de Ingreso: mayo-2015
Mensajes: 3
Antigüedad: 9 años
Puntos: 0
AyudaConexion con base de datos recorrido array

Podrian ayudarme con mi codigo por favor , se guarda el arreglo en la variable pero no suma los valores

Código:
<?php
$suma=0;
$x = 1;
function mostrar_datos($a,$suma,$x){
	if($a != null){
		
		if($a['tienemetro']== 1){
echo 'ID ',$a['id'],'<br>';	
echo 'Ciudad : ',$a['ciudad'],'<br>';
echo 'pais : ',$a['pais'],'<br>';
echo 'habitantes : ',$a['habitantes'],'<br>';
echo 'superficie : ',$a['superficie'],'<br>';
echo 'Tiene Metro : ',$a['tienemetro'],'<br>';	

	
}else {
	echo 'ID ',$a['id'],'<br>';	
echo 'Ciudad : ',$a['ciudad'],'<br>';
echo 'pais : ',$a['pais'],'<br>';
echo 'habitantes : ',$a['habitantes'],'<br>';
echo 'superficie : ',$a['superficie'],'<br>';
echo 'Tiene Metro : ',$a['tienemetro'],'<br>';	
}		
while($x<=10){
		 $suma = $suma + $a['habitantes'];
		$x=$x+1;
	}
	echo $suma,'<br>';
}	
}

$db = mysqli_connect('sql204.byethost7.com','b7_16106679','acsdc120789','b7_16106679_mibasededatos') or
die('error de conexion'.mysql_error);
mysqli_select_db($db, 'b7_16106679_mibasededatos');
$tildes = $db->query("SET NAMES 'utf-8'");
$tabla = mysqli_query($db,'SELECT * FROM ciudades');

while($rows = mysqli_fetch_array($tabla)){
	
	mostrar_datos($rows,$suma,$x);
}

?>