誰かがこの機能をクリーンアップして適切に機能させるのを手伝ってくれませんか?
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>
';
}
}