Jump to content

Formating output of an foreach cycle


criostage

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/247290-formating-output-of-an-foreach-cycle/
Share on other sites

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";

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.