[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

Adding Columns to a Dynamic Table using PHP

I am creating a a dynamic table .  I successfully dynamically generate all but two columns of the table from my first query with no problem.  However, I have reached a curve into the situation I can't figure out.  

I want to add two custom columns at the end of the table.  The first column will come from a second sql statement.  The last column in the table is a simple substraction formula for each row from the latter two columns (i.e col5 - col6 = col8.)  How do I join the data from the second query to the same table as column 6  and add the calculation as column 7 with headings?

1st query
$result = mysql_query("SELECT sampstat as Sampstat, version as Version, variable as Agecat, secondvalue as Sex, total as Total From quotasdetail where ssid = '$ssid' AND Batchnum = '$batch'
               AND market = '$siteid' AND controller = '$controller' order by 'version'", $conn);
if (!$result) {
   echo 'Could not run query: ' . mysql_error();

// Create table from results

    echo "<table  border=1 cellspacing=0 cellpadding=0>";

    echo "<td bgcolor=#E8E8E8><b>".mysql_field_name($result,$r)."</td>";
    echo "<tr>";


    echo "<td>&nbsp;".$row[$r]."</td>";
    echo "</tr>";
    echo "</table>";

Thanks for your help in advance.


1 Solution
It sounds linke you may want to consider joining the two queries using a JOIN statment.  Here is a link that has example JOIN statements, you probably will want to use the INNER JOIN.


Good luck
waynerayAuthor Commented:
I agree with you I need to join two tables to get the output I want.  Additionally, I need to add a calculation added to the sql statement to complete my php table.  I am going to reask my question in the database section.  Thanks.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now