...

View Full Version : Need help :)



Cyber4Hacks
11-25-2011, 05:55 PM
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?

Fou-Lu
11-25-2011, 05:57 PM
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.

Cyber4Hacks
11-25-2011, 06:23 PM
They are not duplicates. This is the db:
http://i.imgur.com/GSvQH.png

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:
http://i.imgur.com/sV5cA.png

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.

Fou-Lu
11-25-2011, 06:53 PM
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.

Cyber4Hacks
11-25-2011, 07:35 PM
I will try to explain again
So..
In the Database there are 2 rows containing the same TID and USER
See on the image:
http://i.imgur.com/GSvQH.png

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

Fou-Lu
11-25-2011, 07:38 PM
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.

Cyber4Hacks
11-25-2011, 07:41 PM
How to use GROUP by ?

Cyber4Hacks
11-25-2011, 07:45 PM
10528

This is the image

Fou-Lu
11-25-2011, 08:03 PM
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?


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

Cyber4Hacks
11-25-2011, 08:05 PM
UID is the ID of the user that voted and the User is the user that posted.

Fou-Lu
11-25-2011, 08:08 PM
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.

Cyber4Hacks
11-25-2011, 08:13 PM
Yes but how this help me for the main problem?

Adee
11-25-2011, 08:20 PM
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

Cyber4Hacks
11-25-2011, 08:27 PM
30 years old and still afraid to click links?

lol

Do you have any idea for the post I made?

Fou-Lu
11-25-2011, 08:28 PM
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.


30 years old and still afraid to click links?

lol

Links are untrustworthy while I'm at work.

Cyber4Hacks
11-25-2011, 08:33 PM
Is it going to work with SELECT DISTINCT? And if yes show me example please ;)

Fou-Lu
11-25-2011, 08:43 PM
No it won't. Not while you query for multiple fields.
Like I said, if you have inconsistencies between your data, you need to figure out why those inconsistencies exist first. The last thing you should worry about at this point is writing an aggregate, especially when the aggregate will carry no value in the context of bad data.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum