打印表数据mysql php [英] Print table data mysql php

查看:73
本文介绍了打印表数据mysql php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试打印表的某些数据时遇到问题.我是这个php mysql的新手,但我认为我的代码是正确的.在这里:

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:

<html>
<body>
<h1>Lista de usuários</h1>
<?php
$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 "<BR/>";
}
mysql_close();
?>

</body>
</html>

echo命令的所有列都存在于数据库的表中.不知道为什么它不打印那些值.

All columns of the echo command exist in my table in the database. Don't get why it's not printing those values.

推荐答案

您将接收到的数据分配为$rows,但是您试图输出变量$row,该变量不存在.

You assigned the received data as $rows, but you are trying to ouput the variable $row, which doesn't exist.

像这样更改它:

while($row = mysql_fetch_array($result))

这篇关于打印表数据mysql php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆