-3

我有一个 PHP 代码,我用它来显示从我的数据库到网页的评论列表。

代码-

while ($row = mysqli_fetch_assoc($query)) { // Loop through results of query

  if ($row['depth'] > $cur_depth) {
   if($row['depth'] == 1){
   echo "<ul>\n";
    runthis();
    $cur_depth = $row['depth'];
   }
    else   if($row['depth'] == 2){
      echo "<ul class='selected'>\n";
      runthat();
      $cur_depth = $row['depth'];
    }
    else{
    echo "<ul>\n";
    runthats();
    $cur_depth = $row['depth'];
    }
  }
  else while ($cur_depth > $row['depth']) {
    echo "</ul>\n";
    $cur_depth--;
  }
  function runthis(){
  echo "<li id=" .$row['depth'] . " class='some_class'>" . $row['comment'] . " &nbsp;id-". $row['category_id'] ."<a href='' id='toggle-cm'>reply</a><br/><div id='commentarea'><textarea row=5 cols=40>write something here...</textarea><br/><button id=" . $row['category_id'] . ">reply to this comment</button></div></li>\n";
  }

  function runthat(){
  echo "<li id=" .$row['depth'] . ">" . $row['comment'] . " &nbsp;id-". $row['category_id'] ."<a href='' id='toggle-cm'>reply</a><br/><div id='commentarea'><textarea row=5 cols=40>write something here...</textarea><br/><button id=" . $row['category_id'] . ">reply to this comment</button></div></li>\n";
  }
}
while ($cur_depth > -1) {
  echo "</ul>\n";
  $cur_depth--;
}

它所做的是从 sql 数据库中获取评论并以分层方式显示它。$row['depth']是存储评论深度的变量。现在,我想为has = 1some_class的元素添加类,并为has = 2 的元素分配一些属性。<li>row['depth']<ul>row['depth']

原始代码运行良好,但我对其进行了一些修改以分配类和属性。

原始代码-

while ($row = mysqli_fetch_assoc($query)) { // Loop through results of query
  if ($row['depth'] > $cur_depth) {
    echo "<ul>\n";
    $cur_depth = $row['depth'];
  }
  else while ($cur_depth > $row['depth']) {
    echo "</ul>\n";
    $cur_depth--;
  }
  echo "<li>" . $row['comment'] . "id-". $row['category_id'] ."<a href='' id='toggle-cm'>reply</a><br/><div id='commentarea'><textarea row=5 cols=40>write something here...</textarea><br/><button id=" . $row['category_id'] . ">reply to this comment</button></div></li>\n";
}
while ($cur_depth > -1) {
  echo "</ul>\n";
  $cur_depth--;
}

现在,我想要实现的是对原始代码进行一些更改,以便将一些不同的属性分配给具有深度的元素<li>row['depth'] = 1并将一些不同的属性应用于深度为<ul>2 的元素。使用修改后的代码时出现错误我展示了。

错误-

Fatal error: Call to undefined function runthat()

我哪里错了?

4

1 回答 1

2

代替:

runthats();

经过

runthat();

并且暂时不要使用该功能

于 2012-08-22T10:08:00.323 回答