phporacle-databaserightnow-crmroql

Displaying one table data with respect to other table


enter image description here

I'm stuck with this problem. I have 2 tables, Invoice and Invoice_Lines. I want to display my table in such a fashion that Invoice lines should be displayed below their respective Invoices. Here is my code:

$queryString = "SELECT * FROM Invoice";
        $roql_result_set = RightNow\Connect\v1_2\ROQL::query($queryString);

        echo "<table class=\"responstable\"><tr><th>ID</th><th>Account</th><th>Contact</th><th>Display Order</th><th>Date Created</th><th>Date Updated</th></tr>"; 
        while($roql_result = $roql_result_set->next())
        {
            while ($row = $roql_result->next())
            {   
                $lines = "SELECT * FROM Invoice_lines";
                $result_set = RightNow\Connect\v1_2\ROQL::query($lines);
                while($result = $result_set->next())
                {
                    while ($line = $result->next())
                    {                       
                        echo "<tr><td><a href=\"#\">" . $line['ID'] ."</a></td><td><a href=\"#\">" . $line['Invoice'] . "</a></td><td>" . $line['Line_Number'] ."</td><td>" . $line['DisplayOrder'] . "</td></tr>"; 

                        $ctime = date('F j, Y' , strtotime($row['CreatedTime']));
                        $utime = date('F j, Y' , strtotime($row['UpdatedTime']));

                        echo "<tr><td><a href=\"#\">" . $row['ID'] ."</a></td><td><a href=\"#\">" . $row['Account'] . "</a></td><td>" . $row['Contact'] ."</td><td>" . $row['DisplayOrder'] ."</td><td>" . $ctime ."</td><td>" .$utime. "</td></tr>";  
                    }
                }

            }
        }
        echo "</table>"; 

Solution

  • Try doing this,

    SELECT Invoice.*, Invoice_lines.* 
      FROM Invoice
      LEFT JOIN Invoice_lines ON Invoice.ID = Invoice_lines.Invoice
       ORDER BY Invoice.Display_order, Invoice_lines.Display_order