PHP获取数据表的数据(所有和单一)

include "config.php" //调用数据库配置

获取数据库所有数据

$sql = mysql_query("select * from user");
$datarow = mysql_num_rows($sql); //长度
//循环遍历出数据表中的数据
for($i=0;$i<$datarow;$i++){
   $sql_arr = mysql_fetch_assoc($sql);
   echo $id = $sql_arr['id']."  ";
   echo $name = $sql_arr['username']."  ";
   echo $pwd = $sql_arr['password']."  ";
   echo $number = $sql_arr['number']."  ";
   echo $regtime = $sql_arr['regtime']."  ";
   echo $ip = $sql_arr['ip']."  ";
   echo $frozen = $sql_arr['frozen'];
   echo "
"; }

获取数据库一行数据的所有数据

$sql = "select * from user where '$username'";
$result = mysql_query($sql);
//$row = mysql_fetch_array($result);
while($row = mysql_fetch_array($result))//这里不能直接使用$row
{
    echo $row['username'] . " " . $row['password'] . " " . $row['number'];
    echo  " " . $row['regtime']. " " . $row['ip'];
    echo "
"; }

你可能感兴趣的:(PHP获取数据表的数据(所有和单一))