获得每个帖子的评论

时间:2014-09-26 17:11:36

标签: php html mysql comments

嗨我必须在我之前执行的各种trhead中创建一个注释系统,并且在注释内部的所有时间内它都可以工作但是很慢并且有很多线程经常会给我超时错误怎么能我解决了这个问题?

function commenti($id) {

$query2 = "SELECT * FROM table2 WHERE numid='$id' ORDER BY id ASC";

$result2 = mysqli_query($conn,$query2);
if($result2->num_rows >0)
 {

  while($row2 = $result2->fetch_array(MYSQLI_ASSOC))
  {
$idt2 =  $row2['id'];

$testot2 = $row2['testo'];

return $testot2;
  }
 } else {
echo "No comment";

}
}


$query = "SELECT * FROM table1 where visualizza='1' ORDER BY id DESC";

$result = mysqli_query($conn,$query);
if($result->num_rows >0)
 {

  while($row = $result->fetch_array(MYSQLI_ASSOC))
  {
$id =  $row['id'];

$titolo = $row['titolo'];




$testo = commenti($id);
echo "$titolo $testo <br>";
}
}

mysqli_close($conn);
?>

2 个答案:

答案 0 :(得分:0)

我会假设你试图提取大量记录。解决此问题的最佳方法是添加分页,每页只加载~10-20条评论。 取决于您的服务器

更新

@OP基本上在首次加载页面时你加载~10条评论,一旦点击查看更多,你就可以使用ajax加载下几页。冲洗并重复。

答案 1 :(得分:0)

我想使用联接,但如果有更多重复也发表评论

$query = "SELECT * FROM table1 left JOIN table2 ON table1.id = table2.numid where visualizza='1' ORDER BY id DESC";