MyBB Community Forums

Full Version: PHP/MySQL Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So..
In the Database there are 2 rows containing the same TID and USER
See on the image:
[Image: 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
(2011-11-25, 07:35 PM)WbDev Wrote: [ -> ]So..
In the Database there are 2 rows containing the same TID and USER
See on the image:
[Image: 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

Try SELECT DISTINCT Smile
Can you give me example how to use it with fetch_array and with this db structure, please?
(2011-11-25, 07:50 PM)WbDev Wrote: [ -> ]Can you give me example how to use it with fetch_array and with this db structure, please?

Try something like this:

$sql = $db->simple_select('SELECT DISTINCT * FROM table');

while($row = $db->fetch_array($sql)) {
    //some code
}

I believe that should work, though I'm not 100%. I tend to ensure I never have duplicate data by fully normalising my table structure during planning.