2017-04-04 18 views
0

如果我們打印「; print_r($ totalteachersget); die;?>我從這個數組中獲取值,然後我們得到下面的數組,現在我想把它作爲行行格式在html中,我的html代碼也在吹 - 請修正我的html代碼。如何從行數組中獲取多個值作爲行格式

---------------------------- ----陣列結果---------------------------------

Array 
(
    [0] => Array 
     (
      [totalteachers] => Array 
       (
        [0] => stdClass Object 
         (
          [teacher_id] => 1 
          [teacher_name] => Amit Rathore 
          [mobile_number] => 99999999 
          [email] => [email protected] 
          [password] => e6e061838856bf47e1de730719fb2609 
          [gender] => male 
          [address] => nothing address 
          [rand_number] => eFhohRkL 
          [status] => 1 
          [created_at] => 2017-01-09 02:24:54 
          [logout_time] => 2017-01-27 
         ) 

       ) 

     ) 

    [1] => Array 
     (
      [totalteachers] => Array 
       (
        [0] => stdClass Object 
         (
          [teacher_id] => 49 
          [teacher_name] => thomas joy 
          [mobile_number] => 
          [email] => [email protected] 
          [password] => 8a6d4494109584e7d36ed19b2dd3cb16 
          [gender] => 
          [address] => 
          [rand_number] => jgqf0RTG 
          [status] => 1 
          [created_at] => 2017-04-01 05:41:50 
          [logout_time] => 
         ) 

       ) 

     ) 

) 

---- --------------------------------- HTML代碼--------------- ------------------

<tbody> 
    <?php if(!empty($totalteachersget)) { 
     $i =1; 
     foreach($totalteachersget as $teacherslist=>$values) { 
      foreach($totalteachers as $secondvalues) {     
      $teacher_id = base64_encode(base64_encode(base64_encode($secondvalues->teacher_id))); 
     ?> 
      <tr class="<?php // echo $bgcolor; ?>"> 
       <td class="col-chk"><!--<input type="checkbox">--></td> 
       <td class="col-first"><?php echo $secondvalues->teacher_name; ?></td> 
       <td class="col-third"><?php echo $secondvalues->mobile_number; ?></td> 
       <td class="col-second"><?php echo $secondvalues->email; ?></td> 
       <td class="col-second"><?php if($secondvalues->status == 0){ echo "Not confirmed"; } else { echo "Confirmed"; } ?></td> 

      </tr> 
     <?php $i++; } } }else{ ?> 
      <tr><td class="col-chk" colspan="10">No records found </td></tr> 
     <?php } ?> 
     </tbody> 
+0

你到底想幹什麼? – Pacio

回答

0

您的循環錯誤。嘗試像這樣,保持HTML的一部分:

foreach ($totalteachersget as $values) { 
    foreach ($values['totalteachers'] as $teacher) { 
     var_dump($teacher->teacher_name); 
    } 
} 
+1

謝謝!我已經完成了你的邏輯和!你的答案也很快。非常感謝 –

0

HTML代碼:

<?php 
if(!empty($totalteachersget)) { 
    foreach($totalteachersget as $offset => $totalteachers) { 
     foreach($totalteachers as $offset1 => $secondvalues) {     
      foreach($secondvalues as $offset2 => $thirdvalues) {     
       $teacher_id = base64_encode(base64_encode(base64_encode($thirdvalues->teacher_id))); 
?> 
       <tr class="<?php // echo $bgcolor; ?>"> 
        <td class="col-chk"><!--<input type="checkbox">--></td> 
        <td class="col-first"><?php echo $thirdvalues->teacher_name; ?></td> 
        <td class="col-third"><?php echo $thirdvalues->mobile_number; ?></td> 
        <td class="col-second"><?php echo $thirdvalues->email; ?></td> 
        <td class="col-second"><?php if($thirdvalues->status == 0){ echo "Not confirmed"; } else { echo "Confirmed"; } ?></td> 

       </tr> 
<?php 
      } 
     } 
    } 
} else { ?> 
    <tr><td class="col-chk" colspan="10">No records found </td></tr> 
<?php } ?> 
</tbody> 
相關問題