Solved

Why is my fucntion only producing one row of results?

Posted on 2011-09-21
3
243 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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…

740 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