Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. <?php
  2.  
  3. function unique_multidim_array($array, $key) {
  4. $temp_array = array();
  5. $i = 0;
  6. $key_array = array();
  7.  
  8. foreach($array as $val) {
  9. if (!in_array($val[$key], $key_array)) {
  10. $key_array[$i] = $val[$key];
  11. $temp_array[$i] = $val;
  12. }
  13. $i++;
  14. }
  15. return $temp_array;
  16. }
  17.  
  18. $finals = array();
  19. $car = '';
  20. $race_name = '';
  21. $divisions = '';
  22. $races = '';
  23. $pilots = array();
  24.  
  25. if( have_rows('champ_division') ):
  26. while( have_rows('champ_division') ): the_row();
  27.  
  28. // vars
  29. $divisions = get_sub_field('division_name');
  30. $races = get_sub_field('division_races');
  31. $pilots = array();
  32. $finals = array();
  33.  
  34. echo '<h4 class="text-uppercase">'.$divisions.'</h4>'; ?>
  35. <table class="table champ_table" id="">
  36.  
  37. <?php
  38. foreach( $races as $post): // variable must be called $post (IMPORTANT)
  39. setup_postdata($post);
  40. while ( have_rows ('race_grid')) : the_row();
  41. while (have_rows('race_pilot')) : the_row();
  42. $pilots[] = get_sub_field('pilot_name');
  43. $finals[] = get_sub_field('final_position');
  44. $penalty = get_sub_field('pilot_penaly');
  45. $bestlap = get_sub_field('pilot_bestlap');
  46. $warn = get_sub_field('pilot_warning'); ?>
  47. <?php endwhile;
  48. endwhile;
  49. endforeach;
  50. wp_reset_postdata();
  51. $drivers = unique_multidim_array($pilots,'display_name');
  52. $race_id = unique_multidim_array($races,'ID');
  53.  
  54. if (!empty($drivers)) { ?>
  55. <thead>
  56. <tr>
  57. <th>Nome do piloto</th>
  58. <th>Carro</th>
  59. <th>Número</th>
  60. <th>Equipe</th>
  61. <?php } foreach( $races as $post): // variable must be called $post (IMPORTANT)
  62. setup_postdata($post);
  63. echo '<th>';
  64. the_title();
  65. echo '</th>';
  66. endforeach;
  67. echo '</tr></thead>';
  68. wp_reset_postdata(); ?>
  69. <?php
  70. foreach ($drivers as $driver) :
  71. $pid = 'user_'.$driver['ID'];
  72. $car = '';
  73. $pnumber = '';
  74. $team = get_field('user_team', $pid);
  75. while ( have_rows ('user_car', $pid) ) : the_row();
  76. $car = get_sub_field('car_model');
  77. $pnumber = get_sub_field('car_number');
  78. endwhile;
  79. ?>
  80. <tbody>
  81. <tr>
  82. <td><?php echo $driver['display_name']; ?></td>
  83. <td><?php if(!empty($car)) { echo $car->post_title;} ?></td>
  84. <td><?php echo $pnumber; ?></td>
  85. <td><?php echo $team; ?></td>
  86. <?php foreach( $races as $post): // variable must be called $post (IMPORTANT)
  87. setup_postdata($post);
  88. echo '<td>';
  89.  
  90. if (in_array($driver, $pilots)){
  91. print_r($finals);
  92. //$warn = get_sub_field('pilot_warning');
  93. //print_r ($penalty);
  94. }
  95. echo '</td>';
  96. //print_r ($group_pilots);
  97. endforeach;
  98. echo '</tr></tbody>';
  99. wp_reset_postdata(); ?>
  100. <?php endforeach; //Piloto Linha ?>
  101. </tr>
  102. </tbody>
  103.  
  104. </table>
  105. <?php // IMPORTANT - reset the $post object so the rest of the page works correctly
  106. endwhile;// IMPORTANT - reset the $post object so the rest of the page works correctly
  107. endif;
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement