2012-05-04 2 views
0

PHP를 사용하여 동적 테이블을 작성하여 MSSQL 데이터베이스의 데이터를 현재 구축중인 사이트의 페이지에 삽입하려고합니다. 보이는 행은 개별 월급을 나타냅니다. 각 행 아래에는 연관된 세부 정보가 있습니다. 이는 각 수표에 대해 기본 테이블 행에 데이터가 보관되어 있기 때문에 세금면에서 쉽습니다. 이제는 공제를 추가해야하며 문제는 각 수표 번호에 대해 여러 행의 세부 공제를받습니다.PHP 및 SQL을 사용하여 다중 문 동적 테이블 만들기

SQL 문 중간 While 루프를 전환 할 수 있지만 끝나면 다시 원래 상태로 전환 할 수 있습니까?

또는이 SQL 마법의 몇 가지 다른 종류의 조인 혼란 외부의 일이다 ....

여기에 내가 지금 가지고있는 코드의 샘플입니다.

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>'); 

위의 섹션에서 다른 쿼리 결과가 필요합니다. 가능한가? 최상의 솔루션?

답변

1

공제를 가져 오는 while 루프에서 두 번째 SQL 쿼리를 수행 할 수 있습니다.

예 : 나는 두 번째 SQL 쿼리에서 여러 결과를 얻을로

$sql1 = "select * from checks"; 
$result1 = mysql_query($sql1); 
while($data1 = mysql_fetch_assoc($result1)){ 
    // output data 

    $sql2 = "select * from deductions where check_id='" . $data1['check_id'] . "'"; 
    $result2 = mysql_query($sql2); 
    while($data2 = mysql_fetch_assoc($result2)){ 
     //output deduction data 
    } 

    // output remaining info 
} 
+0

내가 다른 while 루프가 필요하지 않을까요? –

+0

대답은 '예'입니다. 나는 할 것이다. 하지만 지금은 효과가 있습니다. 대단히 감사합니다. –

+0

예, 코드를 입력했습니다. (결정된). 문제 없습니다, 당신이 듣고있어 기쁘다. – AndrewR