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'].
             ">".$line['App']."</a></td>";
     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

Recommended Answers

All 5 Replies

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.
             ">".$app."</a></td>";
     echo "<td>" . $emp. "</td>";
     echo "<td>" . $server . "</td>";
     echo "</tr>";

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

use mysql distinct query, to query distinct rows.

it still prints the same thing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.