选择不起作用的声明

时间:2017-03-16 19:47:42

标签: php mysqli

在为我的网站创建评论系统时出现问题

选择语句不起作用

   $reslt = mysqli_query($connection,"SELECT * FROM tbl_users where id='".$_SESSION['id']."'");
  $row= mysqli_fetch_array($reslt);

   $comm = mysqli_query($connection,"SELECT * FROM tbl_comments where id='".$_SESSION['id']."'");
     While(  $row= mysqli_fetch_array($comm))

 {
    $comm[] = $row;
 }

如果我删除第二个语句($ comm)第一个语句正常

我的第二个问题

如何从php中的数据库中获取数据?

以下是代码

 $comm = mysqli_query($connection,"SELECT * FROM tbl_comments where id='".$_SESSION['id']."'");
   While(  $row= mysqli_fetch_array($comm))

{
    $comm[] = $row;
}

没有得到结果(评论)

  echo $row['comment']; 

1 个答案:

答案 0 :(得分:0)

不确定您的架构,但可能是这样的:

$result = $connection->query("
SELECT 
  C.comment AS comment, U.user AS user
FROM 
  tbl_comments C, tbl_users U 
WHERE 
  C.id = U.id
");

while($data = $result->fetch_assoc()) {
  echo"$data[comment] by $data[user] </br>";
}