jrodd32 Posted January 29, 2007 Share Posted January 29, 2007 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); elseprint stuff above {[/code]That didn't work. Any suggestions? Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 29, 2007 Share Posted January 29, 2007 http://us2.php.net/array_unique Quote Link to comment Share on other sites More sharing options...
effigy Posted January 29, 2007 Share Posted January 29, 2007 You can also use[tt] SELECT DISTINCT... [/tt]in your SQL. Quote Link to comment Share on other sites More sharing options...
jrodd32 Posted January 29, 2007 Author Share Posted January 29, 2007 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.