Jump to content

Recommended Posts

Hi, i have a fairly compley problem i just can't get my head around. I was hoping you guys could point me in the right direction.

Im using a mysql query that fetches the following table of data:

 

username

mid

rating

testUser

1

10

testUser

2

8

testUser

3

5

dummyUser

1

1

dummyUser

2

3

dummyUser

3

3

 

And i want to display the table on my php-page like this:

 

[/td]

[td]mid:1

mid:2

mid:3

testUser

10

8

5

dummyUser

1

3

3

 

I've tried multiple functions with headache outcomes. I somehow have to assign each users mid rating to his/her username, so that the username only pops up once. Im thinking about storing the data in an array, however this just seems like the dumbest solution. Isn't there an easier way to sort this out?

 

Thanks for your replies.

Best regards

Sorenchr

Link to comment
https://forums.phpfreaks.com/topic/130165-determine-array-row-by-value-search/
Share on other sites

Hey Barand, with your technique

 

Wouldn't the results be a string like

 

testUser      "10 8 5"

dummyUser  "1 3 3"

 

So it would need to be exploded after retrieving to get individual values ?  Or am I getting something wrong. 

 

Dont worry about laPistola man .. you're the sql-superman for rookies like me .. haha .. jk .. but you did help me a few times before.

 

 

Well, by default they would be comma-separated, but at least you would get everything conveniently in a single row for outputting in the desired format.

 

You could do this to aid output in html table

 

SELECT username, GROUP_CONCAT(mid SEPARATOR '</td><td>') as mids
FROM tablename
GROUP BY username

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.