Skip to content
Advertisement

Resetting array pointer in PDO results

I’m having trouble moving from MySQL SELECT methods to PDO methods. I want to iterate through a fetched array twice, both times starting with row zero. In MySQL I would use:

JavaScript

Using PDO methods, I’m not sure how to accomplish the same thing. The code below is how I am trying to do this. The first while loop works fine but the second while loop returns nothing.

JavaScript

Advertisement

Answer

Save your results to an array and then loop that array twice.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement