tags:

views:

41

answers:

3

The title says it all. This is how the query looks like: (simplified)

SELECT * FROM posts WHERE user='37' ORDER BY date DESC

I currently only ave one row in that table, but still for some reason it returns two rows that are exactly the same. At first i thought i messed up with the loop, but i tried printing the returned array out with print_r() and it actually returns two rows.

I tried searching, but i didn't find any similar issues. I do however remember that a friend of mine had the same issue at school, so i'm sure we aint the only ones. I probably just didn't use the right search terms, heh.

Any ideas?

Thanks a bunch!

A: 

Are you sure you only have one row in the table? If so, it seems like the problem must be happening outside of SQL.

What are you doing outside of this query? That seems like the likely source of the issue. You mention a loop: could you be adding the query result to your array twice? Or is the array persisting between calls without being reinitialized (in other words, the result of a previous query is remaining in the array when you don't expect it to)?

djacobson
I just triple checked, and yes i only have one row in the table. I think i found the problem through, and yes, the loop was involved. The issue was that i selected another column_2 while i was looping and selecting column_1. The value of column_1 comes from an array i declared higher up in the code. This is how the query looked like: "SELECT * FROM posts WHERE user='$userId' OR user='$friend' AND date > $limit ORDER BY date DESC".
Nike
+1  A: 

If you have only one record (verify this), it has to be application logic that is duplicating the returned values.

ShaunLMason
A: 

limit 1 is your friend :)

Try adding it to the end of your query.

ChrisBD