Selecting same column multiple times

Reply

Join Date: Dec 2007
Posts: 52
Reputation: mgn2683 is an unknown quantity at this point 
Solved Threads: 0
mgn2683's Avatar
mgn2683 mgn2683 is offline Offline
Junior Poster in Training

Selecting same column multiple times

 
0
  #1
Dec 23rd, 2008
Hi,

This may be hard to describe what I'm trying to do. I have a database table called assignments where there are columns: section, team, and candidate.

For each section, there are 3 teams- 1, 2, 3. The sections are listed alphabetically from A-V. There are 5 candidates per team, so a total of 15 per section. I need to display this for a printer friendly page using dynamic text. For instance:

Section A
Team 1
Candidate_1 Candidate_2 Candidate_3 Candidate_4 Candidate_5

In the database, each candidate has their own row. Modifying the table structure is not an option. Is there any way to pull all candidates from a specific team from different rows to be displayed? Many thanks.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 14
Reputation: mike_g is an unknown quantity at this point 
Solved Threads: 3
mike_g mike_g is offline Offline
Newbie Poster

Re: Selecting same column multiple times

 
0
  #2
Dec 23rd, 2008
If I understand you right, then maybe a query like:
  1. SELECT candidate FROM tablename WHERE team='$team'
Would pull a list/array of all candidates from a given team.

If I understand you wrong, then it might help if you could post your table schema.
Last edited by mike_g; Dec 23rd, 2008 at 3:42 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 5
Reputation: AnDurugkar is an unknown quantity at this point 
Solved Threads: 0
AnDurugkar AnDurugkar is offline Offline
Newbie Poster

Re: Selecting same column multiple times

 
0
  #3
Dec 24th, 2008
following is the answer for your database pull

just query it
  1. select * from assignments where team =$team and section = $section
Thats it

Regards
Last edited by peter_budo; Dec 29th, 2008 at 5:38 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 52
Reputation: mgn2683 is an unknown quantity at this point 
Solved Threads: 0
mgn2683's Avatar
mgn2683 mgn2683 is offline Offline
Junior Poster in Training

Re: Selecting same column multiple times

 
0
  #4
Dec 24th, 2008
I ran a query using this:

  1. SELECT *
  2. FROM assignment
  3. WHERE assignment.Team = $team and assignment.Section = $section

I kept receiving an error saying "1054 - Unknown column '$team' in 'where clause'

Is there any way to modify this?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 148
Reputation: mschroeder is on a distinguished road 
Solved Threads: 25
mschroeder mschroeder is offline Offline
Junior Poster

Re: Selecting same column multiple times

 
0
  #5
Dec 24th, 2008
$team and $section are php variables.

aka

  1. $team = 1;
  2. $section = 'A';
  3.  
  4. $query = 'SELECT *
  5. FROM assignment
  6. WHERE assignment.Team = '.$team.' AND assignment.Section = "'.$section.'"';
Last edited by mschroeder; Dec 24th, 2008 at 1:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Selecting same column multiple times

 
0
  #6
Dec 25th, 2008
can you post your table structure in mysql...
it help to understand and give correct answer to you..

bcoz..how you put your data in column section, team and candidates for 3 teams and for 15 candidates per section is confusing ...

so post your table structure....with example value
Last edited by Aamit; Dec 25th, 2008 at 3:12 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC