Adding Columns to a Dynamic Table using PHP

Posted on 2006-05-09
Last Modified: 2008-03-17
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.


Question by:wayneray
    LVL 4

    Accepted 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

    Author Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now