Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Request Assistance w/Looping

Status
Not open for further replies.

dnayana

Programmer
Nov 14, 2002
53
US
I need another pair of eyes to try to assist me.

What I am trying to do is display records from a view within SQL Server 2000 to the PHP web page. The records are already grouped/sorted on the db backend.

I would like my output to be as follows:


Status: [Value]
Team: [Value]
Manager: [Value]
[List Employees]


Therefore, for each Status display its value once. For each Team, display its value once. For each Manager, display its value once and list his/her employees.

Like this ....
[highlight #FF99FF]
Status: Accepted
Team: Human Resources
Manager: John Doe
Doe, Jane
Park, Deer
Cola, Coke

Manager: Jane Doe different Manager within Team HR
Doe, John
Deer, Park
Coke, Cola

Team: Business different Team but Status = Accepted
Manager: John Doe
Doe, Jane
Park, Deer
Cola, Coke

Status: Assigned new Status
Team: new value
Manager: new value
new value(s)

-- Repeat format until end of records in db --
[/highlight]

The code I've written outputs like this:

Status: Accepted
Team: Human Resources
Manager: Unknown
Doe, Jane

Status: Accepted
Team: To Be Determined (TBD)
Manager: Unknown
Doe, Jane
Park, Deer
Cola, Coke

Status: Assigned
Team: Business
Manager: Unknown
Jackson, Michael

Status: Assigned
Team: Business
Manager: Bird, Larry
Murphy, Eric

Status: Assigned
Team: Business
Manager: Fowler
Marino, Geronimo


However, the employees are within their respective places under the Manager. I just don't understand why the Status and Team are duplicated.

Here's a snippet of the code I've written:

Code:
 ....
		//retrieve the data from the database
		//odbc_fetch_row: Fetch a row 

		  $currentrecord = 0;  //Status
		  $currentrecord2 = 0;  //Team
		  $currentrecord3 = 0;  //HiringManager
						  
		  while($record = odbc_fetch_array($qryresult))

		  	if(($currentrecord == $record['ctrStatus']) && ($currentrecord2 == $record['ctrHomeTeam']) && ($currentrecord3 == $record['ctrHiringManager'])) {
	
				echo ("<tr height=\"18\" colspan=\"3\">"); 
				echo ("<td  style=\"padding-left: 45px\">${record['Candidate']}</td>");
				echo ("</tr>");
				}


			else {

				//Status
			 	echo ("<tr><td><br/></td></tr>");
				echo ("<tr colspan=\"3\" height=\"18\"bgcolor=\"$color\">");
				echo ("<td><b><u>Status: ${record['txtStatus']}</u></b><br/></td>");
				echo ("</tr>");


				//Team			
				echo ("<tr colspan=\"3\">");
				echo ("<td  style=\"padding-left: 20px\"><b>Functional Team: ${record['txtHomeTeam']} (${record['txtHomeTeamAbbrev']})</b><br/></td>");
				echo ("</tr>");

					
				//Hiring Manager
				echo ("<tr colspan=\"3\">");
						echo ("<td  style=\"padding-left: 35px\"><b>Hiring Manager: ${record['HiringManager']}</b><br/></td>");
				echo ("</tr>");

				//Candidate
				echo ("<tr colspan=\"3\">");
				echo ("<td  style=\"padding-left: 45px\">${record['Candidate']}</td>");		
				echo ("</tr>");
				$currentrecord = $record['ctrStatus'];
				$currentrecord2 = $record['ctrHomeTeam'];
				$currentrecord3 = $record['ctrHiringManager'];								
				}


			//disconnect the db
			odbc_close($conn);

Any assistance/guidance is much appreciated.

Thanks,
Nicole [ponytails2]

 
I'm not 100% sure about this, but it looks as though if you fail any of your tests in the if block, then -all- of the following code will be executed. And it does appear that this is what's happening for your sample output; it's failing the if on the manager, but kicking the output out elsewise. You might want to place additional comparison ifs around the first two segments in your else block and see if that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top