Jump to content

php with mysql


sugan

Recommended Posts

Hi,I fetch data's from mysql table and display it in a table format using php as:

usa chriscanada chrisindia chrisfrance mike
I need the format as:
chris usa, canada, indiafrance mike
how to display it in this format?Regards,Suganya
Link to comment
Share on other sites

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...