mysql_connect("localhost","root","");
$sql="SELECT * FROM employees";
$result=mysql_db_query("mydb",$sql);
while($row=mysql_fetch_array($result)) {
printf("First Name:".$row["first"]);
printf("Last Name:".$row["last"]);
printf("Address:".$row["address"]);
printf("Position:".$row["position"]);
}

解决方案 »

  1.   

    $sql="SELECT * FROM employees";
    $result=mysql_db_query($sql);
    while($row=mysql_fetch_array($result)) {
    echo $row["first"];
    .....
    .....
    }
      

  2.   

    代码本身没有问题
    附加排错语句进行检查
    $db = mysql_connect("localhost", "root") or die('连接失败'.mysql_error());
    mysql_select_db("mydb",$db) or die('选库失败'.mysql_error());
    $result = mysql_query("SELECT * FROM employees",$db) or die('查询失败'.mysql_error());
      

  3.   

    代码本身没问题
    我调试结果为:
    First Name: Bob
    Last Name: Smith
    Address: 128 Here St, Cityname
    Position: MarketingManager
    ---------------------------------------------------------
    请确保:
    1\你的数据库密码是否正确,格式为:mysql_connect("localhost", "user","password");
    2\确保你的数据库mydb存在并有表employees
    3\你的建表语句有错:
      id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT,
      去掉DEFAULT '0' .
      

  4.   

    我是楼主,是这样的,我用了$db = mysql_connect("localhost", "root") or die('连接失败'.mysql_error());
    mysql_select_db("mydb",$db) or die('选库失败'.mysql_error());
    $result = mysql_query("SELECT * FROM employees",$db) or die('查询失败'.mysql_error());
    /×××××××××××××××××××××××××××××××/进行排错。页面告诉我
    连接失败Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
    但我已经重启了MYSQL,并且我用命令mysql -u root -p能进入MYSQL。
    我的MYSQL版本是3.23,我的PHP版本是4.3
    怎么解决这个问题?
      

  5.   

    mysql_fetch_array出來的数组需要循环才能显示的
    while($rs=mysql_fetch_array(mysql_query("SELECT * FROM employees"))){
        echo $rs[first];
    }