[PHP] Why a while loop for printing SQL query results?
Go to solution
Solved by Neil,
Because you want to loop while you still have data.
The thing returned by the mysqli functions, iirc, is a resource identifier, not actual data.
You use a while loop to go through it so that you pull the data each time you call your fetch (datatype), and the library internally increased the iterator. Once it's at the end of the iterator, it returns null, and the loop is therefore broken.
Is there a reason you need a for/each loop?
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now