I'm having a problem trying to print some data of a table. I'm new at this php mysql stuff but I think my code is right. Here it is:
Lista de usuários
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="sabs"; // Database name
$tbl_name="doador"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
while($rows = mysql_fetch_array($result)){
echo $row['id'] . " " .$row['nome'] . " " . $row['sobrenome'] . " " .
$row['email'] . " " . $row['login'] . " " . $row['senha'] . " " .
$row['idade'] . " ". $row['peso'] . " " . $row['fuma'] . " " .
$row['sexo'] . " " . $row['doencas'];
echo "
";
}
mysql_close();
?>
All columns of the echo command exist in my table in the database. Don't get why it's not printing those values.
解决方案
You assigned the received data as $rows, but you are trying to ouput the variable $row, which doesn't exist.
Change it like this:
while($row = mysql_fetch_array($result))