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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.