sugan Posted March 25, 2008 Share Posted March 25, 2008 Hi,I fetch data's from mysql table and display it in a table format using php as: usa chriscanada chrisindia chrisfrance mikeI need the format as:chris usa, canada, indiafrance mikehow to display it in this format?Regards,Suganya Link to comment Share on other sites More sharing options...
justsomeguy Posted March 25, 2008 Share Posted March 25, 2008 You will need to use a variable to keep track of which person you last saw. If the current person is the same as the last person then print a comma and the country name. If they are different then save the current person and print his name on its own line, then the country. If your database results aren't sorted by person then you will need to put all the records in an array and sort the array by person first. Link to comment Share on other sites More sharing options...
sugan Posted March 26, 2008 Author Share Posted March 26, 2008 Pls provide me the code.........Regards,Sugan Link to comment Share on other sites More sharing options...
justsomeguy Posted March 26, 2008 Share Posted March 26, 2008 It's not that difficult. It would be better if you want to learn instead of have other people write the code for you. $last = "";while ($row = mysql_fetch_assoc($result)){ if ($row['person'] == $last) { echo ", "; } else { echo "<br>{$row['person']} "; $last = $row['person']; } echo $row['country'];} voila Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.