Jump to content

echo results in html table


bugmero

Recommended Posts

Hi all,

 

how can i put my code , the echo results in a html table :

 

$qres = mysql_query("SELECT * FROM `$clubprefix"."_player` WHERE id='$id'");  

WHILE ($row = mysql_fetch_array ($qres, MYSQL_ASSOC))
{

$FB=$row['FB'];
$FM=$row['FM'];
$SR=$row['SR'];
$Vol=$row['Vol'];
$SS=$row['SS'];
$PS=$row['PS'];
$TE=$row['TE'];



echo "Forehand/Backhand 	:$FB <br>" .
             "Fitness/Movement 		:$FM <br>" .
     "Serve/Return 		:$SR <br>" .
     "Volley			:$Vol <br>" .
     "Special Shots	 	:$FB <br>" .
     "Playing Style	 	:$FB <br>" .
     "Tournament Experience 	:$FB <br>" ;
   

 

i want to put the name and the variable in different columns on the same row

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/201291-echo-results-in-html-table/
Share on other sites

<?php

$qres = mysql_query("SELECT * FROM `$clubprefix"."_player` WHERE id='$id'");  

//Start table and create table headers
$results = "<table>\n";
$results .= "<tr>\n";
$results .= "<th>Forehand/Backhand</th>\n";
$results .= "<th>Fitness/Movement</th>\n";
$results .= "<th>Serve/Return</th>\n";
$results .= "<th>Volley</th>\n";
$results .= "<th>Special Shots</th>\n";
$results .= "<th>Playing Style</th>\n";
$results .= "<th>Tournament Experience</th>\n";
$results .= "</tr>\n";

//Output the data
WHILE ($row = mysql_fetch_array ($qres, MYSQL_ASSOC))
{
    $results .= "<tr>\n";
    $results .= "<td>{$row['FB']}</td>\n";
    $results .= "<td>{$row['FM']}</td>\n";
    $results .= "<td>{$row['SR']}</td>\n";
    $results .= "<td>{$row['Vol']}</td>\n";
    $results .= "<td>{$row['SS']}</td>\n";
    $results .= "<td>{$row['PS']}</td>\n";
    $results .= "<td>{$row['TE']}</td>\n";
    $results .= "</tr>\n";
}
  
//Close the table
$results .= "</table>\n";

?>
<html>
<head></head>

<body>

<div id="tableOutput">
<?php echo $results; ?>
</div>

</body>
</html>

 

I put the results in a variable as it is better form to include the logic at the top of your page and display the results in the body of the page.

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.