criostage Posted September 16, 2011 Share Posted September 16, 2011 Hello i would like to as a little help on how to proper format an foreach output into an HTML table. I have a small function inside an class, that will retrieve the data of an MySQL table and return the result in 1 array, Outside that function i can get the values displayed i only need to format it to show in an table here's what i have: function that gets the data function getfansub(){ $subfanarray = array(); $query = mysql_query("SELECT * FROM anr_fansub WHERE 1"); while($result = mysql_fetch_array($query)){ $subfanarray[] = $result; } return $subfanarray; } Outside the funtion/class $fansubarray = $mysql->getfansub(); VAR_DUMP( $fansubarray ); echo "<br><br>"; foreach($fansubarray as $name){ echo $name['FansubID'] ." ". $name['Designation'] ." ". $name['Website'] ." ". $name['tracker'] ." ". $name['irc'] ."<br>"; } The problem i have with the formating (i really dont know who i can do it) is when he reaches the IRC link he needs to open and close the td and tr brakets of the table. any help or tip is apreciated, thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/247290-formating-output-of-an-foreach-cycle/ Share on other sites More sharing options...
Psycho Posted September 16, 2011 Share Posted September 16, 2011 echo "<table border='1'>\n"; foreach($fansubarray as $name) { echo "<tr>\n"; echo " <td>{$name['FansubID']}</td>\n"; echo " <td>{$name['Designation']}</td>\n"; echo " <td>{$name['Website'}</td>\n"; echo " <td>{$name['tracker'}</td>\n"; echo " <td>{$name['irc']}</td>\n"; echo "</tr>\n"; } echo "</table>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/247290-formating-output-of-an-foreach-cycle/#findComment-1270011 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.