Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-31-2009, 08:53 PM   PM User | #1
unclhos
New to the CF scene

 
Join Date: May 2009
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
unclhos is an unknown quantity at this point
SELECT DISTINCT only one result

I am having a problem with a sql statement using the SELECT DISTINCT. It is only pulling one result from the database when printing the array. Here is the results.
Array ( [0] => 99796-Sponsors [team] => 99796-Sponsors )

Here is the results through myphpadmin

99796-Sponsors
98614-KDP / Future Educators
98239-For Riley
97008-Milan
94795-Team Hope
93583-The Ventilators
93079-Samantha's Team of Love
92200-Chelsea Rainbows
91804-Team Hayden
90293-Individual Walkers - Dalton

Here is the code I am trying to use:
PHP Code:
$select_teams "SELECT DISTINCT team FROM great_strides WHERE file_name = '$_POST[file]'";
$query_teams mysql_query($select_teams)  or die("A MySQL error has occurred.<br />Your Query: " $your_query "<br /> Error: (" mysql_errno() . ") " mysql_error());

$results_teams mysql_fetch_array($query_teams);
  foreach(
$results_teams as $team) {
    
$select_team_leader="SELECT * FROM great_strides WHERE team = '$team' AND position= 'Team Leader'"
Does anyone know why I am only getting the one result and not all possibles?
unclhos is offline   Reply With Quote
Old 05-31-2009, 09:02 PM   PM User | #2
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
You're only fetching one row there:
PHP Code:
$results_teams mysql_fetch_array($query_teams); 
Instead you should loop over all the rows in the resulting resource:
PHP Code:
while ($results_teams mysql_fetch_array($query_teams)){
// do stuff

venegal is offline   Reply With Quote
Users who have thanked venegal for this post:
unclhos (05-31-2009)
Reply

Bookmarks

Tags
distinct, php, sql

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:29 PM.


Advertisement
Log in to turn off these ads.