Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why is my fucntion only producing one row of results?

Posted on 2011-09-21
3
Medium Priority
?
270 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 84

Accepted Solution

by:
Dave Baldwin earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

916 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