我有三个领域。身份证,文章链接地址和日期。这些链接目前正按日期水平填充该页。例如,我有6个链接用于2/26/2017,6个链接用于2/25/2017。我想知道是否有可能添加,当日期改变,日期将在每列的底部,然后有一个水平的断线。然后,它会转到第二天在数据库中。这是我想要的格式。
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);
?>发布于 2017-02-26 22:51:57
我相信这就是你要找的东西,我用你的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> </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>';
?>https://stackoverflow.com/questions/42474162
复制相似问题