有人可以帮助我清理此功能并使其正常工作吗?
它应该看起来像这样: http: //gyazo.com/04c31a3edaabeca5f5c6376f1cb607ca.png 除了在类别下它应该只列出与 cat_id 匹配的类别,它确实有效。
但是页面看起来很奇怪。这就是现在的样子:http: //gyazo.com/f217603bede98210dce21328e1aab34f.png
function getcatposts($cat_id)
{
$sql = mysql_query("SELECT COUNT(*) FROM `topics`");
if(!$sql){
echo 'Error: ',mysql_error();
}
$r = mysql_fetch_row($sql);
$numrows = $r[0];
$rowsperpage = 10;
$totalpages = ceil($numrows / $rowsperpage);
echo '
<table class="table table-striped table-bordered table-hover">
<thead>
<tr class="info">
<th>Title</th>
<th>Username</th>
<th>Date</th>
<th>Category</th>
</tr>
</thead>';
if(isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$sql = mysql_query("SELECT * FROM `topics` ORDER BY topic_id DESC LIMIT $offset, $rowsperpage");
if(!$sql){
echo 'Error: '.mysql_error();
}
$link = mysqli_connect("localhost", "lunar_lunar", "", "lunar_users");
$qc = mysqli_query($link, "SELECT * FROM topics WHERE topic_cat='$cat_id'");
while($row = mysqli_fetch_array($qc))
{
$topic_title[]=$row['topic_subject'];
$topic_id[]=$row['topic_id'];
}
$qc2 = mysqli_query($link, "SELECT * FROM categories WHERE cat_id='$cat_id'");
while($row2 = mysqli_fetch_array($qc2))
{
$cat_name[]=$row2['cat_name'];
}
for ($i=0; $i < count($topic_id); $i++)
{
echo '
<tbody><tr>
<td><a href="topic.php?id='.$topic_id[$i].'">'.$topic_title[$i].'</a></td>
<td><a href="../public.php?id='.$res['topic_by'].'">'.getOwner($res['topic_by']).'</td></a>
<td>'.$res['topic_date'].'</td>
<td>'.$cat_name[$i].'</td>
</tr></tbody>
';
}
}