从数据库计算列然后拉入表格单元格

EDIT: I have successfully been able to calculate the value I was trying to get, but instead of calculating that value for each row, it is just calculating it once and posting that value everywhere. How do I make it recalculate for each row using the code I have?

Picture: http://img515.imageshack.us/img515/9064/example2w.png

New Code:

<html>
<head>
<title>PHP-MySQL Project 4</title>

    <div align="center">
        <p>
            PHP-MySQL Project 4
        <br/>
            By: Ryan Strouse
        </p>
    </div>
</head>
<body bgcolor="#99FFFF">

<?php

$DBName = "surveys";
$DBConnect = @mysqli_connect("localhost", "students", "password")
    Or die("<p>Unable to connect to the database server.</p>"
    . "<p>Error code " . mysqli_connect_errno()
    . ": " . mysqli_connect_error()) . "</p>";

if (!$DBConnect)
    {
    echo "<p> The database server is not available.</p>";
    }
else
    {
    echo "<p> Successfully connected to the database $DBName</p>";
    }

mysqli_select_db($DBConnect, $DBName); 
echo "<p>Database -'$DBName'- found</p>";

$SQLstring = "SELECT * FROM surveys WHERE surveyCode = 'GEI001'";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
echo $SQLstring;
$row = mysqli_fetch_assoc($QueryResult);

$count_surveys = $row['surveyResponses'];

echo "<p>Total Responses: $count_surveys</p>";


$SQLstring2 = "SELECT * FROM results WHERE surveyCode = 'GEI001'";
$QueryResult2 = @mysqli_query($DBConnect, $SQLstring2);
echo $SQLstring2;
echo "<br/>";
$Row = mysqli_fetch_assoc($QueryResult2);


$SQLstring3 = "SELECT * FROM surveys, results";
$QueryResult3 = @mysqli_query($DBConnect, $SQLstring3);
$fetchrow = mysqli_fetch_assoc($QueryResult3);
$result_amount = (($fetchrow['resultResponses'] / $fetchrow['surveyResponses']) * 100);

echo "<table>";
echo "<tr><th>Commercial</th> <th>Views</th> <th>Percentage</th></tr>";
do {
    echo "<tr><td>{$Row['resultDescription']}</td>";
    echo "<td>{$Row['resultResponses']}</td>";
    echo "<td>$result_amount</td></tr>";
    $Row = mysqli_fetch_assoc($QueryResult3);
} while ($Row);
echo "</table>";


?>



<center>
<h3><a href="Survey1.html">Return To Main Page</a></h3>
<h3><a href="../Menu.html">Return to Menu</a></h3>
</center>
</body>

<footer>
<div align="center">
&copy; Copyright Ryan Strouse &copy;

</div>
</footer>
</html>

I have two database tables and I am successfully pulling in column data into a table. The third cell of the table I would like to calculate a percentage out of some of the columns from the database. I'm not sure how to code this... I've tried to come up with something in the SELECT statement from another thread I found with no luck.

Here is a picture of the query I'm trying to get to work: http://img696.imageshack.us/img696/3862/examplegw.png

<html>
<head>
<title>PHP-MySQL Project 4</title>


</head>
<body bgcolor="#99FFFF">

<?php

$DBName = "surveys";
$DBConnect = @mysqli_connect("localhost", "students", "password")
    Or die("<p>Unable to connect to the database server.</p>"
    . "<p>Error code " . mysqli_connect_errno()
    . ": " . mysqli_connect_error()) . "</p>";

if (!$DBConnect)
    {
    echo "<p> The database server is not available.</p>";
    }
else
    {
    echo "<p> Successfully connected to the database $DBName</p>";
    }

mysqli_select_db($DBConnect, $DBName); 
echo "<p>Database -'$DBName'- found</p>";

$SQLstring = "SELECT * FROM surveys WHERE surveyCode = 'GEI001'";
$QueryResult = @mysqli_query($DBConnect, $SQLstring);
echo $SQLstring;
$row = mysqli_fetch_assoc($QueryResult);

$count_surveys = $row['surveyResponses'];

echo "<p>Total Responses: $count_surveys</p>";


$SQLstring2 = "SELECT * FROM results WHERE surveyCode = 'GEI001'";
$QueryResult2 = @mysqli_query($DBConnect, $SQLstring2);
echo $SQLstring2;
echo "<br/>";
$Row = mysqli_fetch_assoc($QueryResult2);


//this is where I am trying to calculate the value and then below it display in table 
//cell # 3
$SQLstring3 = "SELECT *,((resultResponses/surveyResponses)*100) AS AMOUNT FROM surveys, results";
$QueryResult3 = @mysqli_query($DBConnect, $SQLstring3);

do {
    echo "<table>";
    echo "<tr><th>Commercial</th> <th>Views</th> <th>Percentage</th></tr>";
    echo "<tr><td>{$Row['resultDescription']}</td>";
    echo "<td>{$Row['resultResponses']}</td>";
    echo "<td>$QueryResult3</td></tr>";
    $Row = mysqli_fetch_assoc($QueryResult);
} while ($Row);
echo "</table>";


?>



<center>
<h3><a href="Survey1.html">Return To Main Page</a></h3>
<h3><a href="../Menu.html">Return to Menu</a></h3>
</center>
</body>

<footer>

</footer>
</html>

IF I understand what you are asking, you're trying probably to calculate the percentage of a value that you can find in a MySQL query's results. If that is so, then I'd use the function mysql_num_rows to get the total of the records and then in a while and if I'd have a counter of how many times I meet that value.

Then you just do simple math, for example:

result = (100 * counter) / mysql_num_rows

and have a percentage. Then you just echo the result wherever you want! :)

I hope I have understood your question correctly!

$result = mysql_query("SELECT yourRow FROM yourTable");
$aArray = array();
$cont=0;
while($col = mysql_fetch_assoc($result){
   $aArray[$cont] = $col['yourRow'];
   cont++;
}

That should give you a workable array for you to make your math with it and then echo it. Cheers