2017-04-15 154 views
-1

在我的代码中while while循环打印两次输出。这是我的PHP代码:while循环打印两次输出

if($con) 
{ 
    echo '<h1>Connected to MySQL</h1>'; 
    $sql = 'select age, salary from emp'; 
    mysql_select_db('toor'); 
    $retval = mysql_query($sql, $con); 

    if(!$retval) 
     die('could not get data'.mysql_error()); 

    while($row = mysql_fetch_array($retval, MYSQL_NUM)) 
    { 
     echo "age:{$row[0]}<br>"."sal:{$row[1]}<br>"; 
    } 
} 
+0

删除$con请考虑停止使用mysql_ *功能,因为这扩展不支持任何越来越从最新的PHP版本中删除。使用它可能会导致您的产品存在安全漏洞。 –

回答

-1

更换
$row = mysql_fetch_array($retval, MYSQL_NUM)

$row = mysql_fetch_array($retval)

mysql_query()

+1

或者不要使用'mysql_',因为它已被弃用。 – cwallenpoole