在日期变更时有日期标题和中断线路



我有三个字段。ID,文章链接地址和日期。这些链接当前按日期水平填充页面。例如,我有6个链接,用于2017年2月26日,2017年2月25日有6个链接。我想知道是否可以补充说,当日期更改时,日期将在每列的底部出现,然后具有水平断裂线。然后,它将转到数据库中的第二天。这是我想要的格式。

Link1............................Link2...............................Link3
Link4............................Link5...............................Link6
2/25/2017......................2/25/2017...........................2/25/2017
____________________________________________________________________________
Link7............................Link8...............................Link9
Link10...........................Link11..............................Link12
2/26/2017......................2/26/2017...........................2/26/2017
____________________________________________________________________________

<?php
$con = mysql_connect("localhost", "*****", "*****") or
die("Could not connect: " . mysql_error());
mysql_select_db("*****");
$result = mysql_query("select Article from crypto");
// set up loop counter 
$col_count = 0; 
// start table and first tr 
echo '<table border="0" style="width: 100%; table-layout: fixed;"><tr>'; 
while ($row=mysql_fetch_array($result)) { 
   // if you have output 3 cols then end tr and start a new one 
   if ($col_count == 3) { 
      echo '</tr><tr>'; 
      //  and reset the col count 
      $col_count = 0; 
   } 
   // always output the td 
   echo '<td>' . $row['Article'] . '</td>'; 
  // and count the column 
  $col_count++; 
} 
// then close off the last row and the table 
echo '</tr></table>';  
mysql_close($con);
?>

我相信这是您在寻找的东西,如果您想在这里看到该代码,我确实将您的mysql_connect代替了一个简单的数组。 //$ar = array("Link1","Link2","Link3","Link4","Link5","Link6","02/25/17"); //$arz = array("Link1","Link2","Link3","Link4","Link5","Link6","02/26/17");

这应该显示出一种通过在SQL数组的日期中与/匹配的方法来获得所需结果的方法:

<?PHP
$con = mysql_connect("localhost", "*****", "*****") or
die("Could not connect: " . mysql_error());
mysql_select_db("*****");
$result = mysql_query("select Article from crypto");
$col_count = 0; 
// start table and first tr 
echo '<table border="0" style="width: 100%; table-layout: fixed;"><tr>'; 
$row=mysql_fetch_array($result);
foreach($row as $rows) { 
   // if you have output 3 cols then end tr and start a new one 
   if ($col_count == 3) { 
      echo '</tr><tr>'; 
      //  and reset the col count 
      $col_count = 0; 
   } 
   // always output the td 
   if(preg_match("///", $rows, $b)) echo '<td>' . $rows . '</td><td>' . $rows . '</td><td>' . $rows . '</td></tr><tr><td colspan='3'><hr>&nbsp;</td></tr>'; 
   else echo '<td>' . $rows . '</td>';
  // and count the column
  //echo '</tr>';
  $col_count++; 
}
// then close off the last row and the table 
echo '</tr></table>';
?>

最新更新