php - Mysql table getting displayed incorrectly -


there multiple activities(with unique activityid's) campaign(with unique campaignid).for campaignid, activityid's begin 1 , go on , campaignid changes, activityid's begin 1 again.

what want have different table particular campaignid.

what happening right in code every table(for every campaignid), first campaignid's activityids being displayed in tables if use break 1;.if dont use break 1;,then activityids( related campaignids) being displayed in tables.what want have first campaignid's activityids in first table, second campaignid's activityids in second table, , on.any suggestions on how achieve this?

mysql columns:

table campaigns:

  • campaignid
  • campaigndescription
  • campaignlocation
  • numactivities,clientid

table campaignactivities:

  • id
  • campaignid(taken above table)
  • campaigndescription(taken above table)
  • clientid(taken above table)
  • clientfullname
  • activityid
  • activitydescription
  • x1
  • x2
  • x3
  • x4
  • x5
  • y1
  • y2
  • y3

php:

<div class="table-responsive" > <?php        //print rows       $q1=mysqli_query($con,"select * clientusers clientemail='".$_session["email"]."'"); $row1=mysqli_fetch_assoc($q1); $id1=$row1['clientid'];  $q2=mysqli_query($con,"select * campaigns clientid='$id1'"); $row2=mysqli_fetch_assoc($q2); $id2=$row2['clientid'];  $colnames = array(); $data = array();  $data[] = $row2;   while($row2 = mysqli_fetch_assoc($q2))   {      $data[] = $row2;   }   $data=array_reverse($data); $colnames = array_keys(reset($data)); $colnames =array($colnames[2],$colnames[6],$colnames[1]);        foreach($data $val)        {             echo "<tr>";           ?><div class="well">           <?php             $q3=mysqli_query($con,"select * campaignactivities clientid='$id2'");       $row3=mysqli_fetch_assoc($q3);        $colnames2 = array();       $data2 = array();       $data2[] = $row3;       while($row3 = mysqli_fetch_assoc($q3))       {         $data2[] = $row3;       }        $colnames2 = array_keys(reset($data2));       $colnames2 =array($colnames2[5],$colnames2[6],$colnames2[7],$colnames2[8],$colnames2[9],$colnames2[10],$colnames2[11],                           $colnames2[12],$colnames2[13],$colnames2[14]);      ?>   <table class="table table-condensed table-striped table-bordered table-hover no-margin well">       <tbody>       <tr>       <?php         $temp=1;       foreach($data2 $val2)        {            echo "<tr>";           if ($temp>(int)$val2[$colnames2[0]]) {$temp=1;break 1;}            else {$temp=(int)$val2[$colnames2[0]]; echo "</tr>";};           foreach($colnames2 $colname2)           {              echo "<td>".$val2[$colname2]."</td>";           }         }          ?>   </tr>    </tbody>    </table><?php echo "</div><br>";} ?> </div> 

if understand correctly have groups of data being returned single sql query. each group of data (where first item in group having 1 stored in field name stored in $colnames2 ) want put out separate html table.

normally kind of issue check field want trigger change, , when change needed output end of 1 table , start if next. output first start table before loop , last end table after loop.

you use class tables this. create new object class before loop, each time group changes unset object , create new one, , unset object after loop. in class put out start of table in constructor , end of table in destructor. this:-

<div class="table-responsive" > <?php        //print rows $q1=mysqli_query($con,"select * clientusers clientemail='".$_session["email"]."'"); $row1=mysqli_fetch_assoc($q1); $id1=$row1['clientid'];  $q2=mysqli_query($con,"select * campaigns clientid='$id1'"); $row2=mysqli_fetch_assoc($q2); $id2=$row2['clientid'];  $colnames = array(); $data = array(); $data[] = $row2; while($row2 = mysqli_fetch_assoc($q2)) {     $data[] = $row2; } $data=array_reverse($data); $colnames = array_keys(reset($data)); $colnames =array($colnames[2],$colnames[6],$colnames[1]); foreach($data $val) {       echo "<tr>";     ?><div class="well">     <?php       $q3=mysqli_query($con,"select * campaignactivities clientid='$id2'");     $row3=mysqli_fetch_assoc($q3);      $colnames2 = array();     $data2 = array();     $data2[] = $row3;     while($row3 = mysqli_fetch_assoc($q3))     {         $data2[] = $row3;     }      $colnames2 = array_keys(reset($data2));     $colnames2 =array($colnames2[5],$colnames2[6],$colnames2[7],$colnames2[8],$colnames2[9],$colnames2[10],$colnames2[11],                         $colnames2[12],$colnames2[13],$colnames2[14]);      $atable = new atable();     $temp=1;      foreach($data2 $val2)     {          if ($temp>(int)$val2[$colnames2[0]])          {             $temp = 1;             unset($atable);             $atable = new atable();         }         $atable->write_line($colnames2, $val2)     }      unset($atable);      echo "</div><br>";}   ?> </div>  <?php class atable {     function __construct()     {         echo "<table class='table table-condensed table-striped table-bordered table-hover no-margin well'> <tbody>  <tr>";     }      function __destruct()     {         echo "</tr> </tbody> </table>";     }      function write_line($colnames2, $val2)     {         foreach($colnames2 $colname2)         {              echo "<td>".$val2[$colname2]."</td>";         }      } }  ?> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -