php - Display text once within for loop on the first loop -


i have sql query inside loop , want echo of success of these query once. here part of code

<?php     for($i=0;$i<sizeof($assigned_project_id);$i++){     $sql2="select * assign_task inner join branch on assign_task.branch_id=branch.branch_id project_id=".$assigned_project_id[$i]." , user_id=1";                                  $query2=mysqli_query($con,$sql2);    if(mysqli_num_rows($query2)>0){                  echo" have assigned following reports";              }                  while($row2=mysqli_fetch_assoc($query2)){                        echo $row2['branch_id']."&nbsp;".$row2['branch_name']."<br/>";                  }                }              ?>

i want display "you have assigned following reports" once. please me.

use below

<?php        $test =0 ;        for($i=0;$i<sizeof($assigned_project_id);$i++){              $sql2="select * assign_task inner join branch on assign_task.branch_id=branch.branch_id project_id=".$assigned_project_id[$i]." , user_id=1";              $query2=mysqli_query($con,$sql2);             if(mysqli_num_rows($query2)>0){                if($test==0){                    echo" have assigned following reports";                   $test++;                }             }             while($row2=mysqli_fetch_assoc($query2)){                  echo $row2['branch_id']."&nbsp;".$row2['branch_name']."<br/>";             }          }         ?> 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -