Php 从数据库中选择数据的问题

Php 从数据库中选择数据的问题,php,mysql,mysqli,Php,Mysql,Mysqli,我使用此代码在编辑页面上显示用户已经对其进行了注释的文本,如果他们愿意,我想让他们对其进行编辑,但我在使用mysqli_num_行检查它们是否有结果时遇到了一个问题,我从数据库中没有得到任何结果。为什么我用错误的方法从数据库中进行选择 $editsql = "SELECT topics.topic_id, topics.topic_subject, topics.topic_by, posts.post_id, posts.post_topic, posts.post_content F

我使用此代码在编辑页面上显示用户已经对其进行了注释的文本,如果他们愿意,我想让他们对其进行编辑,但我在使用mysqli_num_行检查它们是否有结果时遇到了一个问题,我从数据库中没有得到任何结果。为什么我用错误的方法从数据库中进行选择

    $editsql = "SELECT topics.topic_id, topics.topic_subject, topics.topic_by, posts.post_id, posts.post_topic,
posts.post_content
FROM topics, posts WHERE posts.post_topic = ".mysqli_real_escape_string($conn,$_GET['id'])." ";
$editresult = mysqli_query($conn,$editsql);
if(mysqli_num_rows($editresult) == 0)
  {
      echo 'something went wrong please try again later';
  }
      while ($editrow= mysqli_fetch_assoc($editresult)) {
  $topic_by = $editrow['topic_by'];
  if ($_SESSION['id'] = $topic_by) {
  echo '<form method="post" action="'.edit_function($conn).'" class="textareacon bottom">
      <textarea name="edit-content">'.$editrow['post_content'].'</textarea>
      <input type="submit" value="Submit reply" name="edit-post" class="topicsubmit"/>
  </form>';
}else {
  echo "sorry look like you've been redirected to the wrong topic please head back and try again";
}



}
$editsql=“选择topics.topic\u id,topics.topic\u主题,topics.topic\u by,posts.post\u id,posts.post\u主题,
posts.post_内容
从主题,posts WHERE posts.post_topic=“.mysqli_real_escape_string($conn,$\u GET['id'])”;
$editresult=mysqli_查询($conn,$editsql);
if(mysqli_num_rows($editresult)==0)
{
echo“出现问题,请稍后再试”;
}
而($editrow=mysqli\u fetch\u assoc($editresult)){
$topic_by=$editrow['topic_by'];
如果($\u会话['id']=$topic\u by){
回声'
“.$editrow['post_content']”
';
}否则{
echo“抱歉,看起来您被重定向到了错误的主题,请返回并重试”;
}
}

当没有结果时,您正试图获得结果。请按以下方式更改代码并重试。我还通过

$editsql = "SELECT topics.topic_id, topics.topic_subject, topics.topic_by, posts.post_id, posts.post_topic, posts.post_content FROM topics, posts WHERE posts.post_topic = ".mysqli_real_escape_string($conn,$_GET['id'])." ";

$editresult = mysqli_query($conn,$editsql);

if(mysqli_num_rows($editresult) == 0) {
    echo 'something went wrong please try again later';
} else {
      while ($editrow= mysqli_fetch_assoc($editresult)) {
          $topic_by = $editrow['topic_by'];
          if ($_SESSION['id'] == $topic_by) {
              echo '<form method="post" action="'.edit_function($conn).'" class="textareacon bottom"><textarea name="edit-content">'.$editrow['post_content'].'</textarea><input type="submit" value="Submit reply" name="edit-post" class="topicsubmit"/></form>';
          } else {
              echo "sorry look like you've been redirected to the wrong topic please head back and try again";
          }
      }
}
$editsql=“选择topics.topic\u id,topics.topic\u主题,topics.topic\u by,posts.post\u id,posts.post\u主题内容,posts WHERE posts.post\u主题=“.mysqli\u real\u escape\u string($conn,$\u GET['id')”;
$editresult=mysqli_查询($conn,$editsql);
if(mysqli_num_rows($editresult)==0){
echo“出现问题,请稍后再试”;
}否则{
而($editrow=mysqli\u fetch\u assoc($editresult)){
$topic_by=$editrow['topic_by'];
如果($\u会话['id']==$topic\u by){
回显'.$editrow['post_content'].';
}否则{
echo“抱歉,看起来您被重定向到了错误的主题,请返回并重试”;
}
}
}
个人提示:请尝试使用和/或


我发现问题好像出现在我的主题页面上

  while($row = mysqli_fetch_assoc($result))
  {
  if ($_SESSION['id'] = $post_by) {
      echo '<br /><a class="edit_topic" href="edit-topic.php?id='.$row['id'].' ">Edit</a><br /><br />';
  }
}
while($row=mysqli\u fetch\u assoc($result))
{
如果($\u会话['id']=$post\u by){
回音“


”; } }
我使用了数据库中的一行,我应该使用从url获取id

  if ($_SESSION['id'] = $post_by) {
      $get_id = mysqli_real_escape_string($conn,$_GET['id']);
      echo '<br /><a class="edit_topic" href="edit-topic.php?id='.$get_id.' ">Edit</a><br /><br />';
  }
if($\u会话['id']=$post\u by){
$get\u id=mysqli\u real\u escape\u字符串($conn,$\u get['id']);
回音“


”; }

谢谢你的帮助,我的问题已经解决了

如果你完全改变了问题,你应该关闭并重新打开一个新问题我不能因为一些奇怪的原因它说我应该等几天才能发布一个新问题然后你应该等它说Sam试图从我的论坛系统得到一个结果一切都设置正确主题和帖子我只想让用户如何制作主题能够编辑它。我试图选择主题主题以显示给用户进行编辑,但它不会显示主题已经存在,帖子也不会显示给用户,但出于某种奇怪的原因,它告诉我没有找到数据库您是否尝试过在没有php的情况下对数据库运行查询,通过PhpMyAdmin之类的东西?mysqli是否可以避免握手?mysqli和PDO之间的区别是什么?mysqli本身并不安全,PDO和mysqli之间的区别离你只有一步之遥。关于这个主题的文章有数百篇(如果不是数千篇的话)。如果它解决了您的问题,请接受此答案,或者询问与此相关的问题。这行代码
如果($\u SESSION['id']=$post\u by){
是错误的,除非您试图将
$post\u by
的值分配给
$\u SESSION['id']
。如果($\u SESSION id']=$post\u by){$post\u by=$row['post\u by'];我已经给帖子指定了一个值。(是的,但只使用1个等号,你就可以将所有读到的内容都指定给会话值。我只是将其调整为2个等号。你对我上面的新Q有什么答案吗?你需要发布一个新问题。你不能在一篇帖子中编辑和询问更多内容。