943,845 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 707
  • PHP RSS
Dec 23rd, 2008
0

Selecting same column multiple times

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
mgn2683 is offline Offline
63 posts
since Dec 2007
Dec 23rd, 2008
0

Re: Selecting same column multiple times

If I understand you right, then maybe a query like:
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 12
Solved Threads: 3
Newbie Poster
mike_g is offline Offline
14 posts
since Jul 2008
Dec 24th, 2008
0

Re: Selecting same column multiple times

following is the answer for your database pull

just query it
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AnDurugkar is offline Offline
5 posts
since May 2008
Dec 24th, 2008
0

Re: Selecting same column multiple times

I ran a query using this:

PHP Syntax (Toggle Plain Text)
  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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
mgn2683 is offline Offline
63 posts
since Dec 2007
Dec 24th, 2008
0

Re: Selecting same column multiple times

$team and $section are php variables.

aka

PHP Syntax (Toggle Plain Text)
  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.
Sponsor
Reputation Points: 265
Solved Threads: 126
Practically a Master Poster
mschroeder is offline Offline
624 posts
since Jul 2008
Dec 25th, 2008
0

Re: Selecting same column multiple times

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.
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: two submit buttons calling 2 different functions - PHP
Next Thread in PHP Forum Timeline: Count page views??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC