我做了我的SQL請求,這樣在我model.php:顯示結果SELECT *
public function getUserForAdmin() {
$arrayUser = $this->bdd->getArray('SELECT prenom AS prenomUFA, nom AS nomUFA, email AS emailUFA, cp AS cpUFA FROM user');
return $arrayUser['prenomUFA'];
}
在我的index.php我這樣稱呼它
$userForAdmin = $user->getUserForAdmin();
echo $userForAdmin['prenomUFA'];
有了這個,我剛纔的我prenom領域的第一個字母導致...
我陣列的輸出:
Array (
[0] => Array ([prenom] => Coline [nom] => [email] => hj [userForAdmin] => 69570)
[1] => Array ([prenom] => Coline [nom] => [email] => [email protected] [userForAdmin] => 69570)
[2] => Array ([prenom] => Coline [nom] => [email] => [email protected] [userForAdmin] => 69570)
[3] => Array ([prenom] => Coline [nom] => [email] => hjkjk [userForAdmin] => 69570)
[4] => Array ([prenom] => Coline [nom] => [email] => [email protected] [userForAdmin] =>)
[5] => Array ([prenom] => Coline [nom] => [email] => hjkhjk [userForAdmin] => 69570)
[6] => Array ([prenom] => Coline [nom] => jkljl [email] => [email protected] [userForAdmin] =>)
[7] => Array ([prenom] => Coline [nom] => fgdfg [email] => [email protected] [userForAdmin] =>)
[8] => Array ([prenom] => Coline [nom] => ghjg [email] => [email protected] [userForAdmin] => ghj)
[9] => Array ([prenom] => ghj [nom] => ghjghj [email] => [email protected] [userForAdmin] =>)
[10] => Array ([prenom] => hjkhk [nom] => hjkhjk [email] => [email protected] [userForAdmin] =>)
[11] => Array ([prenom] => cvbcb [nom] => cvbcvb [email] => [email protected] [userForAdmin] =>)
[12] => Array ([prenom] => jhk [nom] => hjkhjk [email] => [email protected] [userForAdmin] =>)
[13] => Array ([prenom] => Coline [nom] => [email] => cghjghj [userForAdmin] => 45645)
[14] => Array ([prenom] => Coline [nom] => [email] => ghj [userForAdmin] => 44545)
)
$ arrayUser是數組,但$ arrayUser ['userForAdmin']不是數組。它是數組中'userForAdmin'鍵的值。所以echo'
'。$ userForAdmin。'
';對我來說似乎很好。 – Ashish 2014-10-08 13:16:35@colinec請你詳細說明你想輸出的內容。你的代碼說它從數據庫表中取出名爲'user'的行。然後,您將結果集的第一行存儲在變量$ arrayUser中。在下一個語句中,您將使用$ arrayUser ['userForAdmin']返回存儲在'cp'列中的值(您在查詢中給出'userForAdmin'的別名)。 – Ashish 2014-10-08 13:30:02
對不起,我想輸出我的所有字段,從我的SELECT中詢問。像:prenom,nom,email和cp。我意識到我的AS只是在推崇我的CP。如果我把所有的領域都放在AS中,那麼如何將它們歸還給它? – colinec 2014-10-08 13:33:02