2016-09-06 80 views
0

我有一个问题,我不知道如何解决... 我有页的评论和页面的回复。 向下是我的代码,一切正常,它显示我想要的所有内容,但问题是,当我点击评论转到带有回复的页面时,它得到的id是错误的。评论回复select not working good

例如:对于第一条评论,我需要id = 1,第二id = 2等等。但是我得到id = 1,其中user_id = 1而不是评论中的id。 对不起,我的英文。

<?php 
    $id = $show['id']; 
    $sq = "SELECT * FROM comments, users WHERE comments.user_id = users.id"; 
    $re = mysqli_query($dbCon, $sq);           
    while($abc=mysqli_fetch_assoc($re)){ 
?> 
    <div class="card hoverable q_area"> 
     <div class="card-content"> 
      <div class="chip"> 
       <img src="<?php echo $show['profile_foto'] ?>">      
     <?php echo $abc['user'] . " said:"; ?> 
      </div><br /> 
      <div id="comm"> 
     <?php $a=substr(str_replace(' ','-',$abc['question']), 0, 50); ?> 
       <h5><a href="replys.php?id=<?php echo $abc['id'] ?>&reply=<?php echo $a ?>"> 
     <?php echo $abc['comment']; ?></a></h5> <br /> 
      </div> 
     </div> 
    </div> 
     <?php } ?> 

如果我改变这种选择是这样的:

$sq = "SELECT * FROM comments"; 

然后链接ID的工作,但我不能回应说谁该评论的用户。

database tables: 
users - id, user, pass 
comments- id, user_id, comment 

请帮我:(

回答

0

改变你的query - $sq这一个:

$sq = "SELECT a.*, b.user FROM comments as a, users as b WHERE a.user_id = b.id"

+0

我刚刚做了5分钟前。但这是答案。非常感谢。 – TooFast

0

你只是一个NEDD别名在您选择;

$sq = "SELECT *, comments.id as comment_id FROM comments, users WHERE comments.user_id = users.id"; 

而且你的链接会出现一些这样的:

<h5><a href="replys.php?id=<?php echo $abc['comment_id'] ?>&reply=<?php echo $a ?>"> 

希望我帮助过了。

+0

谢谢你,但不是正确的答案。 :) – TooFast