Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Need help :)

  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help :)

    Need help with this:

    Basically it takes the data from the database table and fetches the array and displays each row of the table BUT it duplicates the rows because the db structure is like this:

    id, tid, uid, user, vote

    id is the ID of the vote
    tid is the link ID where the vote has been done
    uid is the User ID
    user is the Username
    vote is the Vote that the user made (1-10)

    When a user votes it adds it to the db (new row) and then if another user votes for the same link it makes new row too and displays 2 results in the table(page where the votes are displayed, not db).

    Any help, please?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    And your question is what? Duplicates exist and will show in your dataset depending on what you are querying for.

    Also, in the future please select a title that better describes the issue.

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    They are not duplicates. This is the db:


    These with yellow are in the table. But I want to sum the vote and display the link and the username not twice.

    Here is the table with the duplicates:


    See? TEST is 2 times displayed. I already made the Vote to SUM. I just want to display link and username only once in the table.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Upload the images directly if you want to show them, I won't follow links out.

    Your description still does not indicate a conflict. You indicated that two records would be inserted, one for each user. By duplicates, I meant the tid, so you can expect that you will receive duplicates for tid within the output generated.
    The images may show what you are wanting to do, so upload those to the forums. Also post the query you are using.

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I will try to explain again
    So..
    In the Database there are 2 rows containing the same TID and USER
    See on the image:


    When I fetch_array the sql that selects everything from this db
    It displays the 2 rows in the table
    I mean 2 of them same user same tid and same vote in the table
    I just want when fetch_array to display only 1 row
    Where in the db are with same tid and user
    and the vote to be with SUM and to sum the both rows in the db

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Like I said I won't follow links out while I'm at work.
    Same tid for the same user on a SUM indicates that you are missing a GROUP BY in your query.

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How to use GROUP by ?

  • #8
    New Coder
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Need help :)-asxasx.png

    This is the image

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You can't with what you have. Since the voteid exists within the selection, it must also be a part of the group by, so each record will still show. If you remove the voteid, you can query it using: SELECT tid, uid, user, SUM(tid) AS vote FROM table GROUP BY user, uid.
    I thought the uid was the userid posting; what is the difference between the uid and user?

    Edit:
    Sorry my bad. That should be SUM(vote) not sum of tid. Tack tid onto the GROUP BY as well.

  • #10
    New Coder
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    UID is the ID of the user that voted and the User is the user that posted.

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by Cyber4Hacks View Post
    UID is the ID of the user that voted and the User is the user that posted.
    The image shows differently. Admin and Admin do not share the same UID, but one of the Admin shares the same UID as Admin2. Without the UID being consistent to match the user, the group by will be broken by one or the other.
    If the UID can be used to retrieve the user name from an alternate table, I'd just drop that user field completely and use a join to pull data out from another table.

  • #12
    New Coder
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes but how this help me for the main problem?
    Last edited by Cyber4Hacks; 11-25-2011 at 09:20 PM.

  • #13
    Regular Coder
    Join Date
    Jul 2010
    Location
    Oregon City
    Posts
    280
    Thanks
    5
    Thanked 50 Times in 49 Posts
    Quote Originally Posted by Fou-Lu View Post
    Upload the images directly if you want to show them, I won't follow links out.
    30 years old and still afraid to click links?

    lol

  • #14
    New Coder
    Join Date
    Nov 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Adee View Post
    30 years old and still afraid to click links?

    lol
    Do you have any idea for the post I made?

  • #15
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by Cyber4Hacks View Post
    Yes but how this help me for the main problem?
    Effectively without properly matching uid and user you cannot group these together. Since it will never consider a row with uid=2 and user=Admin2 to match a row uid=2 and user=Admin, the result will still be two separate entries. If there is a conflict between the user names and uid's not matching what they should be, I think you have a bigger problem to worry about then aggregating the data at this point.

    Quote Originally Posted by Adee View Post
    30 years old and still afraid to click links?

    lol
    Links are untrustworthy while I'm at work.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •