I’m trying to build a dynamic table using PHP to insert data from a MSSQL database into a page for a site I’m building. Each visible row represents an individual paycheck. Below each row is the details associated with it. That was easy for taxes as the data is held within the primary table row for each check. Now I need to add deductions and the issue is, for each check number, I get multiple rows of detail deductions.
Can I switch SQL statement mid While loop but then switch back to the original when I’m done?
Or is this a job for a confusing outer join of some other sort of SQL Wizardry….
Here’s a sample of the code I have now.
while ($row = mssql_fetch_array($rs))
{
$paychecknum =$row['check_no'];
$paycheckdate=$row['check_date'];
$netpay=$row['check_amount'];
$grosspay=$row['gross_pay'];
$tax=$row['taxes'];
$deductions=$row['deductions'];
$fit=$row['fit'];
$lit=$row['lit'];
$sit=$row['sit'];
$fica=$row['fica'];
echo('<div class="row">');
echo('<div class="cell">Check Date:');
echo $paycheckdate;
echo('</div>');
echo('<div class="cell">Check Number: ');
echo $paychecknum;
echo('</div>');
echo('<div class="cell">Gross Pay: ');
echo $grosspay;
echo('</div>');
echo('<div class="cell clickable" onClick="showAmount('.$paychecknum.')"> Taxes: ');
echo $tax;
echo('</div>');
echo('<div class="cell clickable" onClick="showAmount(1'.$paychecknum.')">Deductions: ');
echo $deductions;
echo('</div>');
echo('<div class="cell">Net Pay: ');
echo $netpay;
echo('</div>');
echo('</div>');
echo('<div class="row hidden" id="'.$paychecknum.'">');
echo('<div class="cell">Federal Income Tax: ');
echo $fit;
echo('</div>');
echo('<div class="cell">Local Income Tax: ');
echo $lit;
echo('</div>');
echo('<div class="cell">State Income Tax: ');
echo $sit;
echo('</div>');
echo('<div class="cell">FICA: ');
echo $fica;
echo('</div>');
echo ('</div>');
echo ('<div class="row hidden" id="1'.$paychecknum.'">');
#### echo('<div> Deductions go here'); ######Where I need my details###
echo('</div>');
echo ('</div>');
For the section noted, I need the results of a different query. Is it possible? Best possible solution?
You can do a second SQL query in the
whileloop that pulls in the deductions.Example: