打印查询,打印一些场1次,打印一些领域多次

问题描述:

我不知道如果我想打印我的$ STA和$ STB一次,我应该怎么做,但打印我的$测试aslong正如我在数据库中找到他们, $ STA和$机顶盒是唯一的关键,但在每个STA很多$测试和机顶盒打印查询,打印一些场1次,打印一些领域多次

<?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>"); 

现在,当我在while循环的印刷这样的兼得。

$sta 
    $stb 
    $test 

    $sta 
    $stb 
    $test 

    $sta 
    $stb 
    $test 

    $sta 
    $stb 
    $test 

,但我想它来打印这样

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

任何suggetions?在此先感谢

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

OK谢谢你,给我一些时间 – Moe

+0

莫名其妙的还是循环和写作就像 – Moe

+0

以前那样BTW。你在if(i == 0)处忘了$ s​​ign? – Moe