Solved

Why is my fucntion only producing one row of results?

Posted on 2011-09-21
3
235 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 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 36577668
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
ID: 36577687
Duh...sorry.  Thanks.  Working perfectly now.  Have a good one.
0
 

Expert Comment

by:esoftconsult
ID: 36577694
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

803 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