Skip to content
Advertisement

PHP Loop through results

I am trying to loop through my database and check to see if the user already exists in another table. If they do then I want to increment a value, if they don’t then I want to add the user.

When I run the code below it happily loops through all the results:

However when I add in the SQL to check to see if they exist in the other table the loop no longer functions correctly and echos the same user each time.

Advertisement

Answer

In the open eye: Rename the inside $result variable. It is over writting the first $result.

It could be the problem. Not tested though.

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