Jump to content

Duplicates in arrary from mySQL


jrodd32

Recommended Posts

I am trying to remove the duplicates from an array that is being created from a mySQL database. 

The array is created like this:

[code] function init_coaches($coach,$email,$sport)
{
   if (!($db = @mysql_connect(*, '*','*')))
   {;
     print 'Temporarily unable to connect to database server. Please try again later.';
     exit;
   }
   mysql_select_db('Scoreboard',$db);
   global $coaches;
   $coaches=mysql_fetch_array(mysql_query("SELECT KHSAA_Schools.* FROM KHSAA_Schools where member=\"T\""));
   global $coachlist;
   $coachlist=mysql_query("SELECT $coach, school, $email, address1, address2, city, zip, phone, athphone, faxphone FROM KHSAA_Schools WHERE member=\"T\" and $sport=\"T\" order by school");
}[/code]

and accessed like this:

[code]while($coaches=mysql_fetch_array($coachlist))
    {
      printf('%-25s ',$coaches[$coach]);
      printf('%-30s ',$coaches[school]);
      printf('%-20s ',$coaches[city]);
      printf('%-20s ',$coaches[phone]);
      printf('%-20s ',$coaches[faxphone]);
      printf('%-50s ',$coaches[$email]);
      print('<br>');
    }
    print ("Total: $count");[/code]

I tried to put this in as a fix:

[code]    if(in_array($coaches[$coach], $coaches))
      next($coaches);
    else
print stuff above
    {[/code]

That didn't work.  Any suggestions?
Link to comment
Share on other sites

Because the query is looking for superintendants they are in charge of more than one school.  Does that make the each of the results different?

I implymented the array_unique like this:

[code] if($coaches=mysql_fetch_array($coachlist))
    {
    $nodup=array();
    $nodup=array_unique($coaches);
    while($nodup=mysql_fetch_array($coachlist))
    {
      printf('%-25s ',$nodup[$coach]);
      printf('%-30s ',$nodup[school]);
      printf('%-20s ',$nodup[city]);
      printf('%-20s ',$nodup[phone]);
      printf('%-20s ',$nodup[faxphone]);
      printf('%-50s ',$nodup[$email]);
      print('<br>');
    }
    }[/code]

or is that not the proper way to use that function?, because I am still getting the same duplicates.

Could I just search for repeating names?
Link to comment
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.