不显示任何数据

时间:2018-04-23 16:37:08

标签: php mysql

这是我的php和mysql代码。它不显示任何数据。请告诉我我的错误在哪里:

   <?php
    $ddaa = mysql_query("SELECT ref FROM users WHERE id='$uid'");
    $mallu2 = mysql_query("SELECT mallu FROM users WHERE id='$ddaa'");
    $result = mysql_fetch_array($mallu2);
    echo $result['mallu'];
    ?>

1 个答案:

答案 0 :(得分:0)

您可以使用 Mysqli ,不推荐使用mysql 一个小例子:

连接数据库测试

$mysqli = new mysqli('127.0.0.1', 'user', 'password', 'test');
if ($mysqli->connect_errno) {
 echo "Error: Errot on connection : \n";
    echo "Errno: " . $mysqli->connect_errno . "\n";
}

//查询

$sql = "SELECT ref FROM users WHERE id=$uid";

//如果没有结果

if ($resultado->num_rows === 0) {
    echo "we can't find data with  $uid. try again !.";
    exit;
}

//打印结果

while ($dato = $resultado->fetch_assoc()) {
echo $dato['ref'];
}

Mysqli Php documentation