Solved

Why is my fucntion only producing one row of results?

Posted on 2011-09-21
3
224 Views
Last Modified: 2012-05-12
Experts,

I am trying to create a function which will loop through my DB and pull all of the information for the given querey.  I can confirm that the query below should be pulling two rows of data...but, it only pulls one row.  It is like the while loop is just running once.

Can someone help me make the while loop gather all rows of data?
function get_rows(){
	$nuid = $_GET['nuid'];
	$man_report_sql = "SELECT * FROM schedule WHERE ManagerNUID='".$nuid."'";
	$man_report_query = mysql_query($man_report_sql);
	while($result = mysql_fetch_array($man_report_query)){
		if($result['showed']=='1'){$showed='Yes';}
		if($result['showed']=='0'){$showed='No';}
		$tbl = '
		<tr align="center">
		<td style="background-color:#efffde;">'.$result['JobAssignDescription'].'</td>
		<td style="background-color:#efffde;">'.$result['UserField13'].'</td>
		<td style="background-color:#efffde;">'.$result['EmpFirstName'].'</td>
		<td style="background-color:#efffde;">'.$result['EmpLastName'].'</td>
		<td style="background-color:#efffde;">
		'.$result['JobStartTime'].' '.$result['StartAMPM'].'<br />'.$result['JobEndTime'].' '.$result['EndAMPM'].'
		</td>		
		<td style="background-color:#efffde;">
		'.$result['expected'].'
		</td>		
		<td style="background-color:#efffde; border-right:2px solid #000000;">
		'.$result['notes'].'
		</td>
		<td style="background-color:#fffeba;">
		'.$result['coding'].'
		</td>
		<td style="background-color:#fffeba;">'.$showed.'</td>
		</tr>';
	}//END WHILE STATEMENT;
	return $tbl;
}//END FUNCTION

$rows = get_rows();

echo $rows;

Open in new window

0
Comment
Question by:evibesmusic
3 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
Because you are over-writing $tbl each time instead of adding to it.   Define $tbl at the top of your function as $tbl = "";  Then where you have "$tbl =" use "$tbl .=" instead so the text will be appended each time.
0
 

Author Closing Comment

by:evibesmusic
Comment Utility
Duh...sorry.  Thanks.  Working perfectly now.  Have a good one.
0
 

Expert Comment

by:esoftconsult
Comment Utility
Hi,

get_rows returns string value of $tbl, which is getting set (or re-set) for every while cycle.  You better do incremental .= instead of =.

Something like
$tbl .= '
      <tr align="center">

Good Luck!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now