如果数据库中没有数据,则为空白<td>

时间:2019-06-18 08:45:57

标签: php mysql

我有带有以下字段的表

________________________________________
|link|organic|social|total|addedby|dateadded|
______________________________________________
|test|   5   |   2  |  3  | Test  | 17-06-2019

我每周从星期五获取数据

<?php
  if(isset($_GET['month']) && $_GET['month']!='')
  {
    $choosenmonth=$_GET['month']." ".date('Y') ;
  }
  else {
    $choosenmonth= date('M Y');
  }

  $given_year = strtotime($choosenmonth);
  $for_start = strtotime('Friday', $given_year);
  $for_end = strtotime('+1 month', $given_year);


  for ($i = $for_start; $i <= $for_end; $i = strtotime('+1 week', $i)) { ?>
    <th><?php   echo date('l Y-m-d', $i); ?></th>
  <?php } ?>

  ----------------------------------------------------
  07-06-2019  | 15-06-2019  |  21-06-2019 | 21-06-2019





  select sum(total)as totalsum, sum(organic) as organic , sum(social) as social from traffic where (STR_TO_DATE(dateadded, '%d-%m-%Y') between '".$str2."' and '".$weekdate."') and link='".$alllinks['link']."' group by link";

  $colors=$conn->query($qy);

  while($color=$colors->fetch_assoc())
  {
    ?> 
    <td> <?php  if ($colors->num_rows)  { ?> <strong>O</strong>-<?php echo $color['organic']; ?>, <strong>S</strong>-<?php echo $color['social']; ?>, <strong>T</strong>-<?php echo $color['totalsum']; ?> <?php } else{ echo "<td>No data</td>"; } ?>
    </td> 
<?php  }?>

一切都很好,但如果该周没有可用的移动数据,则允许移动。如果数据不可用,我想要空白的td单元格。

0 个答案:

没有答案