2016-09-22 6 views
1

$ staと$ stbを一度印刷したいのですが、 $ STAと$ STBは一意のキーですが、私はこのようなwhileループの印刷の両方を持っている場合、多くの$すべてのSTAでのテストと今STBwhileループでクエリを印刷し、いくつかのフィールドを一度印刷し、何度も何度か印刷します。

<?php 
    //Establish connection to database 
    $host = "*****"; 
    $conn = *******; 
    $query = " Select * 
    from p100f 
    LEfT OUTER JOIN ***** test **** 
    where p100sta = 1 AND p100stb = 1 



//Execute query 
$queryexe = db2_exec($conn, $query) ; 
//Fetch results 


while(db2_fetch_row($queryexe)) { 

$sta = db2_result($queryexe, 'p100sta'); 
$stb = db2_result($queryexe, 'p100stb'); 
$test = ****test****** 

    print("<div class='text-center'> 
    <h2>$sta and $stb</h2>  <---------- this one i want to only print once 
    $test  <------------------- this one i want it to repeat aslong 
as i find them in database 
</div>"); 

があります。

$sta 
    $stb 
    $test 

    $sta 
    $stb 
    $test 

    $sta 
    $stb 
    $test 

    $sta 
    $stb 
    $test 

が、私はそれがこの

$sta 
    $stb 
    $test 
    $test 
    $test 
    $test 
    $test 

任意のsuggetionsのように印刷したいですか?事前のおかげで

答えて

1
Try this code 


//Execute query 
$queryexe = db2_exec($conn, $query) ; 
//Fetch results 

$i=0; 
while(db2_fetch_row($queryexe)) { 

$sta = db2_result($queryexe, 'p100sta'); 
$stb = db2_result($queryexe, 'p100stb'); 
$test = ****test****** 

    print("<div class='text-center'> 

    if($i==0) 
    { 
     <h2>$sta and $stb</h2>  <---------- this one i want to only print once 
    } 
    else 
    { 
     continue; 
    } 
    $test  <------------------- this one i want it to repeat aslong 
as i find them in database 
</div>"); 
$i++; 
}//while closed 
+0

は大丈夫、それはところで – Moe

+0

は何とかそのはまだループと書いていくつかの時間を欲しがる、ありがとうございました。 if(i == 0)で$記号を忘れましたか? – Moe

+0

前に行ったよう – Moe

関連する問題