我有三个字段。 id,文章链接地址和日期。链接当前按日期水平填充页面。例如,我有2个用于2/26/2017的链接和用于2/25/2017的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);
?>
答案 0 :(得分:0)
我相信这就是你要找的我用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>';
?>