我正在尝试使用JSON和ajax显示来自我的数据库的数据,但我在执行该操作方面遇到了困难。请帮助,谢谢。
//我的js函数
function show_messages(){
$.ajax({
url: "display_table.php",
cache: false,
success: function(html){
$("#table_content").html(html);
}
});
}
<?php
$ query =“SELECT * FROM comments
ORDER BY id ASC”;
$ result = mysql_query($ query);
if(isset($_REQUEST['AnswerId'])){ $AnswerId = $_REQUEST['AnswerId']; }
else {$AnswerId = 0; }
$i=0;
while ($mytablerow = mysql_fetch_row($result)){
$mytable[$i] = $mytablerow;
$i++;
}
function tree($treeArray, $level, $pid = 0) {
global $AnswerId;
if (! $treeArray)
{ return; }
foreach($treeArray as $item){
if ($item[1] == $pid){
?>
<div class="CommentWithReplyDiv" style="margin-left:<?php echo($level*60);?>px">
<div class="CommentDiv">
<div class="User"><?php echo($item[2]) ; ?></div>
<div class="Message"><?php echo($item[3]) ; ?></div>
<div class="Date"><?php echo($item[4]) ; ?></div>
<?php
if ($level<=10)
{ echo '<a href="" class="ReplyLink" onclick="AnswerComment('.$item[0].');return false;">Reply</a>'; }
echo '<a href="" class="DeleteLink" onclick="DeleteComment('.$item[0].');return false;">Delete</a>';
?> </div> <?php
if ($AnswerId == $item[0]){
?><div id="InnerDiv"><?php
ShowForm($AnswerId);
?></div><?php
}
?> </div> <?php
echo ('<br/>');
tree($treeArray, $level+1, $item[0]);
}
} }
tree($mytable, 0);
?>