Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJames Barrett
13,253 PointsWhy does the array return the same value twice?
array(1) { [0]=> array(16) { ["U_ID"]=> string(1) "1" [0]=> string(1) "1" ["U_Forename"]=> string(5) "James" [1]=> string(5) "James" ["U_Surname"]=> string(7) "Barrett" [2]=> string(7) "Barrett" ["U_Email"]=> string(25) "james-barrett@hotmail.com" [3]=> string(25) "james-barrett@hotmail.com" ["U_Password"]=> string(8) "password" [4]=> string(8) "password" ["U_Team"]=> string(7) "Arsenal" [5]=> string(7) "Arsenal" ["U_Biography"]=> string(19) "Hi there I am James" [6]=> string(19) "Hi there I am James" ["U_Activated"]=> string(1) "1" [7]=> string(1) "1" } }
I am working on my own project and the fetchAll() returns an array of the result. However why is it two-dimensional and why is it returning the same value twice?
Thanks, James.
1 Answer
Henrik Hansen
23,176 PointsBecause fetchAll() returns both the associated array (column names as key) as well as the numerical array. You can set the fetch mode as an argument: PDO fetchAll
Or you can use the regular fetch() witch returns one row at a time, and loop it to get all the rows from your query.
James Barrett
13,253 PointsJames Barrett
13,253 PointsApologies for formatting of the code... I did indent it however it did not do it correctly :S