title: Calculate columns from database then pull into table cell
body: <p>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?</p>
  
  <p>Picture: <a href="http://img515.imageshack.us/img515/9064/example2w.png" rel="nofollow">http://img515.imageshack.us/img515/9064/example2w.png</a></p>
  
  <p>New Code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;PHP-MySQL Project 4&lt;/title&gt;
  
      &lt;div align="center"&gt;
          &lt;p&gt;
              PHP-MySQL Project 4
          &lt;br/&gt;
              By: Ryan Strouse
          &lt;/p&gt;
      &lt;/div&gt;
  &lt;/head&gt;
  &lt;body bgcolor="#99FFFF"&gt;
  
  &lt;?php
  
  $DBName = "surveys";
  $DBConnect = @mysqli_connect("localhost", "students", "password")
      Or die("&lt;p&gt;Unable to connect to the database server.&lt;/p&gt;"
      . "&lt;p&gt;Error code " . mysqli_connect_errno()
      . ": " . mysqli_connect_error()) . "&lt;/p&gt;";
  
  if (!$DBConnect)
      {
      echo "&lt;p&gt; The database server is not available.&lt;/p&gt;";
      }
  else
      {
      echo "&lt;p&gt; Successfully connected to the database $DBName&lt;/p&gt;";
      }
  
  mysqli_select_db($DBConnect, $DBName); 
  echo "&lt;p&gt;Database -'$DBName'- found&lt;/p&gt;";
  
  $SQLstring = "SELECT * FROM surveys WHERE surveyCode = 'GEI001'";
  $QueryResult = @mysqli_query($DBConnect, $SQLstring);
  echo $SQLstring;
  $row = mysqli_fetch_assoc($QueryResult);
  
  $count_surveys = $row['surveyResponses'];
  
  echo "&lt;p&gt;Total Responses: $count_surveys&lt;/p&gt;";
  
  
  $SQLstring2 = "SELECT * FROM results WHERE surveyCode = 'GEI001'";
  $QueryResult2 = @mysqli_query($DBConnect, $SQLstring2);
  echo $SQLstring2;
  echo "&lt;br/&gt;";
  $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 "&lt;table&gt;";
  echo "&lt;tr&gt;&lt;th&gt;Commercial&lt;/th&gt; &lt;th&gt;Views&lt;/th&gt; &lt;th&gt;Percentage&lt;/th&gt;&lt;/tr&gt;";
  do {
      echo "&lt;tr&gt;&lt;td&gt;{$Row['resultDescription']}&lt;/td&gt;";
      echo "&lt;td&gt;{$Row['resultResponses']}&lt;/td&gt;";
      echo "&lt;td&gt;$result_amount&lt;/td&gt;&lt;/tr&gt;";
      $Row = mysqli_fetch_assoc($QueryResult3);
  } while ($Row);
  echo "&lt;/table&gt;";
  
  
  ?&gt;
  
  
  
  &lt;center&gt;
  &lt;h3&gt;&lt;a href="Survey1.html"&gt;Return To Main Page&lt;/a&gt;&lt;/h3&gt;
  &lt;h3&gt;&lt;a href="../Menu.html"&gt;Return to Menu&lt;/a&gt;&lt;/h3&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  
  &lt;footer&gt;
  &lt;div align="center"&gt;
  &amp;copy; Copyright Ryan Strouse &amp;copy;
  
  &lt;/div&gt;
  &lt;/footer&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>Here is a picture of the query I'm trying to get to work: <a href="http://img696.imageshack.us/img696/3862/examplegw.png" rel="nofollow">http://img696.imageshack.us/img696/3862/examplegw.png</a></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;PHP-MySQL Project 4&lt;/title&gt;
  
  
  &lt;/head&gt;
  &lt;body bgcolor="#99FFFF"&gt;
  
  &lt;?php
  
  $DBName = "surveys";
  $DBConnect = @mysqli_connect("localhost", "students", "password")
      Or die("&lt;p&gt;Unable to connect to the database server.&lt;/p&gt;"
      . "&lt;p&gt;Error code " . mysqli_connect_errno()
      . ": " . mysqli_connect_error()) . "&lt;/p&gt;";
  
  if (!$DBConnect)
      {
      echo "&lt;p&gt; The database server is not available.&lt;/p&gt;";
      }
  else
      {
      echo "&lt;p&gt; Successfully connected to the database $DBName&lt;/p&gt;";
      }
  
  mysqli_select_db($DBConnect, $DBName); 
  echo "&lt;p&gt;Database -'$DBName'- found&lt;/p&gt;";
  
  $SQLstring = "SELECT * FROM surveys WHERE surveyCode = 'GEI001'";
  $QueryResult = @mysqli_query($DBConnect, $SQLstring);
  echo $SQLstring;
  $row = mysqli_fetch_assoc($QueryResult);
  
  $count_surveys = $row['surveyResponses'];
  
  echo "&lt;p&gt;Total Responses: $count_surveys&lt;/p&gt;";
  
  
  $SQLstring2 = "SELECT * FROM results WHERE surveyCode = 'GEI001'";
  $QueryResult2 = @mysqli_query($DBConnect, $SQLstring2);
  echo $SQLstring2;
  echo "&lt;br/&gt;";
  $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 "&lt;table&gt;";
      echo "&lt;tr&gt;&lt;th&gt;Commercial&lt;/th&gt; &lt;th&gt;Views&lt;/th&gt; &lt;th&gt;Percentage&lt;/th&gt;&lt;/tr&gt;";
      echo "&lt;tr&gt;&lt;td&gt;{$Row['resultDescription']}&lt;/td&gt;";
      echo "&lt;td&gt;{$Row['resultResponses']}&lt;/td&gt;";
      echo "&lt;td&gt;$QueryResult3&lt;/td&gt;&lt;/tr&gt;";
      $Row = mysqli_fetch_assoc($QueryResult);
  } while ($Row);
  echo "&lt;/table&gt;";
  
  
  ?&gt;
  
  
  
  &lt;center&gt;
  &lt;h3&gt;&lt;a href="Survey1.html"&gt;Return To Main Page&lt;/a&gt;&lt;/h3&gt;
  &lt;h3&gt;&lt;a href="../Menu.html"&gt;Return to Menu&lt;/a&gt;&lt;/h3&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  
  &lt;footer&gt;
  
  &lt;/footer&gt;
  &lt;/html&gt;
  </code></pre>