Jump to content

Recommended Posts

I have a mysql table that consists of the following columns: START_DATE, TEAM_ID.
What I want to do is run a query that retrieves distinct START_DATE values and then all of the distinct TEAM_ID values that are in the same result row as the distinct START_DATE values. In case Im being a little confusing, in mysql I have:
|START_DATE|TEAM_ID|
|200608|6|
|200608|6|
|200608|7|
|200608|7|
|200609|4|
|200609|4|

What Id like to do then is retrieve the unique dates, and the unique teamids for that date, so something like:|200608 => 6,7|200609 => 4|

This is what I have so far:
$test3 = @mysql_query("SELECT DISTINCT DATE_FORMAT(START_DATE,'%Y%m') AS date, TEAM_ID AS teamid from sf_team_player WHERE OLDCLUB_ID IS NOT NULL ORDER BY START_DATE DESC");
$rows = mysql_num_rows($test3);

for($i=0;$i<$rows;$i++)
{
$tid = mysql_result($test3,$i,'teamid');
$date = mysql_result($test3,$i,'date');
$testarr[$date] = $tid;
}

The above returns an array telling me the number of teamids (theyre not unique though, which is part of the problem) that exist whenever the START_DATE is $date. Now how can I bring that teamid number down by ignoring duplicates (Im having trouble adjusting my query for that, Im pretty sure that is where the problem is) and creating a multidimensional query that will not only tell me the number of unique teamids whenever START_DATE is $date but also show them to me?

Help much appreciated...
mkosmosports
Link to comment
https://forums.phpfreaks.com/topic/34366-queryarray-question/
Share on other sites

I'm surprised that the teamids are not unique from that query.  DISTINCT should return unique rows only.

To get the structure you want, I would use
[code=php:0]$testarr[$date][] = $tid[/code]

Then you get the teamids for each date in an array.

I'm interested to see what your actual output is from that query.
Link to comment
https://forums.phpfreaks.com/topic/34366-queryarray-question/#findComment-161779
Share on other sites

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.