Sql query returns only first row

前端 未结 2 537
南方客
南方客 2021-01-24 09:16

I\'m try to display a result of a select query, but i only get duplicate first row not all the rows. here is my code :

$query = \"SELECT Email from client\";
$r         


        
2条回答
  •  暖寄归人
    2021-01-24 10:08

    You need to use fetchALL() as fetch() only returns one row according to the docs:

    Fetches a row from a result set associated with a PDOStatement object.

    $query = "SELECT Email from client";
    $result = $db->query($query)->fetchALL();
    foreach($result as $email){
        echo $email["Email"]."\n";
    }
    

提交回复
热议问题