php - SQL JOINS retrieving and displaying twice -


I am joining 2 tables and am trying to show results. The only problem is that every result has been repeated. I have 2 tables, messages, and follow messages are a fixed user input, and I want to show it only to specific people who follow some users.

  Message | Follow -id -id -message -mem1 (logged-in user) -userid -mem2 (user followed) -product $ display = ""; $ Sql ​​= mysql_query ("Select" to join me as a message to me.Userid = fl.mem2 WHERE fl.mem1 = $ id (user entered) ORDER me.created DESC LIMIT 10 $ ($ Line = mysql_fetch_array ($ query)); $ {$ = $ line ["id"]; $ message = $ row ["message"]; $ userid = $ row [ "Userid"]; $ made = $ line ["created"]; $ Display. = "& Lt ;? Php echo $ userid ;? & Gt ;: & lt ;? Php ek $ message ;; & Gt; & Lt; Br / & gt; & Lt ;? Php echo $ made ;; & Gt; ";}   

There are no duplicates in the database, just by recovering. Thanks for the input!

Edit: Display code < / Div>

You "double" results are most likely because the query results in something different. < P> If I understand your tablespace correctly; You have followers with one-to-many relationships with messages.

In your query, however, you can send messages and followers Each line will contain a unique combination message & lt; & gt; Followers.

In short, when a message has two followers , You will find two rows in the result with the same message; but a different follower entry.

If you want to show each message once, and then list all followers of each follower, You are either group You can use the functions of (like group_concat) and group-by-message entries. Secondly, once you retrieve the message line, the followers will be able to get them into a different query, After that the results of that question have to be printed as a follower of that message.

If you are just trying to get the number of followers; You can use a group on the UID of your message table and add count on the UID or User ID of the follower table. (Do not do this with the group, should not be selected *, but can make different columns.)

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -