Profile image for Gabriel Feippe feippe
Código básico para conectar a MySQL con PHP y recorrer los resultados.
Language
PHP
Tags
connect mysql mysql_fetch_array php result
Favorited By
Profile image for Gabriel Feippe Profile image for Juan Urbina

Conectar y recorrer resultados en MySQL con PHP

1 mysql_connect($db_server,$db_user,$db_password); 2 mysql_select_db($db_name); 3 4 $sql="SELECT id, name, email FROM users WHERE active=1"; 5 6 $result=mysql_query($sql); 7 8 if($result!=NULL){ 9 if(mysql_num_rows($result)>0){ 10 while($row=mysql_fetch_array($result){ 11 //here you can work with the results... 12 echo "ID: ".$row['id']." NAME: ".$row['name']." EMAIL: ".$row['email']; 13 } 14 }else{ 15 //no results, you can put a message here... 16 } 17 mysql_free_result($result); 18 } 19 20 mysql_close();

Comments