无法从数据库PHP、AJAX检索数据
这是我在这里的第一篇文章。 我正在制作一个简单的网站,用户可以在其中发表评论,其评论将保存在数据库中。 我在数据库中创建了一个包含三列“id”、“name”、“comment”(name不是imp)的表。 现在我想做一个“查看更多”按钮。我在根目录“config.php”、“index.php”、“ajax\u more.php”中有三个文件 这是我的ajax_more.php无法从数据库PHP、AJAX检索数据,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,这是我在这里的第一篇文章。 我正在制作一个简单的网站,用户可以在其中发表评论,其评论将保存在数据库中。 我在数据库中创建了一个包含三列“id”、“name”、“comment”(name不是imp)的表。 现在我想做一个“查看更多”按钮。我在根目录“config.php”、“index.php”、“ajax\u more.php”中有三个文件 这是我的ajax_more.php <?php include("config.php"); if(isSet($_P
<?php
include("config.php");
if(isSet($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$result=mysql_query("select * from commenttable where id<'$lastmsg' order by id desc limit 5");
$count=mysql_num_rows($result);
while($row=mysql_fetch_array($result))
{
$id=$rows['id'];
$name=$rows['name'];
$comment=$rows['comment'];
?>
<li>
<?php echo "#" . $id . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="0"/>'; ?>
</li>
<?php
}
?>
<div id="more<?php echo $id; ?>" class="morebox">
<a href="#" id="<?php echo $id; ?>" class="more">more</a>
</div>
<?php
}
?>
将您的while
语句更改为foreach
,如下所示:
$row=mysql_fetch_array($result);
foreach($row as $key)
{
$id=$key['id'];
$name=$key['name'];
$comment=$key['comment'];
?>
<li>
<?php echo "#" . $id . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="0"/>'; ?>
</li>
<?php
}
?>
<div id="more<?php echo $id; ?>" class="morebox">
<a href="#" id="<?php echo $id; ?>" class="more">more</a>
</div>
<?php
}
?>
$row=mysql\u fetch\u数组($result);
foreach($行作为$key)
{
$id=$key['id'];
$name=$key['name'];
$comment=$key['comment'];
?>
那么,您是否进行过任何调试以缩小问题范围?错误将出现在php中。不应该$comment=$rows['comment'];
是$comment=$row['comment']
?是的,我尝试了很多方法,但似乎都不管用。我只想在某个按钮上从数据库加载旧的注释或数据。hrmm。我希望isSet()只是一个打字错误。它是写的isSet()你能在$id=$key['id']之前添加一行打印($key);
以及打印($dblink)吗
它起作用了错误出现在$comment=$rows['comment'];be$comment=$row['comment'];
<?php
mysql_connect("mysql17.000webhost.com","a1360777_tester","9868364058?");
mysql_select_db("a1360777_test");
$name=$_POST['name'];
$comment=$_POST['comment'];
$submit=$_POST['submit'];
$dbLink = mysql_connect("mysql17.000webhost.com", "a1360777_tester", "9868364058?");
mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);
if($submit)
{
if($comment)
{
$insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') ");
?>
<script type="text/javascript">
window.location = "http://sonymobile.comule.com/";
</script>
<?php
}
else
{
echo "Please Fill out all Fields";
}
}
?>
$row=mysql_fetch_array($result);
foreach($row as $key)
{
$id=$key['id'];
$name=$key['name'];
$comment=$key['comment'];
?>
<li>
<?php echo "#" . $id . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="0"/>'; ?>
</li>
<?php
}
?>
<div id="more<?php echo $id; ?>" class="morebox">
<a href="#" id="<?php echo $id; ?>" class="more">more</a>
</div>
<?php
}
?>