i m trying to extract multiple rows and print it in a single line in a web page.
My code

while ($line = mysql_fetch_array($app, MYSQL_ASSOC)) 
     echo "<tr><td>";
     echo "<a href=AssignedUpdateForm.php?app=".$line['App'].
     echo "<td>" . $line['firstName'] ." ". $line['surname'] . "</td>";
     echo "<td>" . $line['ServerName'] . "</td>";
     echo "</tr>";		

outputs this:

Application    employee	Server
   z	         a	 c
   z	         b	 c
   z	         a	 d
   z	         b	 d

however i want it to output

Application    employee	Server
   z	         a,b	 c,d

can someone help please

7 Years
Discussion Span
Last Post by babydol

You need a variable to keep the prev application read (we'll call it $app).
As you read through all the z rows, you build two variables (let's call them $emp and $server). Every time you add one, you are giving it a trailing comma. When $app changes, you then drop the last trailing commas and then crank out the actual table line:

echo "<tr><td>";
     echo "<a href=AssignedUpdateForm.php?app=".$app.
     echo "<td>" . $emp. "</td>";
     echo "<td>" . $server . "</td>";
     echo "</tr>";

Edited by chrishea: n/a


i tried that but it just throws alot of errors such as undefined variable emp, undefined variable server and Resource id #11

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.