我是刚学php 在操作时候出现以下错误,大家看看是怎么了,网上说是数据表损坏了,可是我修复后还是这样
错误提示如下:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 4 in D:\wamp\www\myPhp\selectFile.php on line 14Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 4 in D:\wamp\www\myPhp\selectFile.php on line 15Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 4 in D:\wamp\www\myPhp\selectFile.php on line 16我的程序代码是
<?php
$conn=mysql_connect("localhost","root","") or die("连接数据库服务器失败");
mysql_select_db("mydate",$conn)or die("选择数据库失败");
$result=mysql_query("select count(*) from tb_user");
$total=mysql_result($result,0,0);
?>
<table width="650" border="1">
<?php
if($total)
{
$result=mysql_query("select * from tb_user");
for($i=0;$i<=$total;$i++)
{
$id=mysql_result($result,$i,'id');
$username=mysql_result($result,$i,'username');
$password=mysql_result($result,$i,'password');
?>
<tr>
<td><?php echo $id ?></td>
<td><?php echo $username?></td>
<td><?php echo $password?></td>
</tr>
<?php
}//end for
} else {
?>
<tr>
<td colspan="3">没有数据</td>
</tr>
<?php
}
?>
</table>
<?php
mysql_free_result($result);
mysql_close($conn);
?>
错误提示如下:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 4 in D:\wamp\www\myPhp\selectFile.php on line 14Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 4 in D:\wamp\www\myPhp\selectFile.php on line 15Warning: mysql_result() [function.mysql-result]: Unable to jump to row 1 on MySQL result index 4 in D:\wamp\www\myPhp\selectFile.php on line 16我的程序代码是
<?php
$conn=mysql_connect("localhost","root","") or die("连接数据库服务器失败");
mysql_select_db("mydate",$conn)or die("选择数据库失败");
$result=mysql_query("select count(*) from tb_user");
$total=mysql_result($result,0,0);
?>
<table width="650" border="1">
<?php
if($total)
{
$result=mysql_query("select * from tb_user");
for($i=0;$i<=$total;$i++)
{
$id=mysql_result($result,$i,'id');
$username=mysql_result($result,$i,'username');
$password=mysql_result($result,$i,'password');
?>
<tr>
<td><?php echo $id ?></td>
<td><?php echo $username?></td>
<td><?php echo $password?></td>
</tr>
<?php
}//end for
} else {
?>
<tr>
<td colspan="3">没有数据</td>
</tr>
<?php
}
?>
</table>
<?php
mysql_free_result($result);
mysql_close($conn);
?>
为什么不用mysql_fetch_row之类的函数呢
为什么不用mysql_fetch_row之类的函数呢
while($row=mysql_fetch_array($result))
{
echo '用户名是:' . $row['username'];
echo '密码是:' . $row['password'];
}
这样就可以打印所有信息了
$result=mysql_query("select count(*) from `tb_user`");
改为
for($i=0;$i < $total;$i++)