Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why is my fucntion only producing one row of results?

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

715 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