php循环显示问题,请大家帮帮我.

来源:百度知道 编辑:UC知道 时间:2024/09/25 22:19:52
<body>
<?php

$host="localhost"; $user="root"; $password="123456";

$dbase_name="liuyanban"; $table_name="lyb_hh";

$conn=mysql_connect($host,$user,$password) or
die ("连接数据库服务器失败。".mysql_error());
echo "数据库服务器: $host 用户名称:$user <br>";

mysql_select_db($dbase_name,$conn) or
die ("连接数据库失败。".mysql_error());
echo "数据库: $dbase_name 数据表: $table_name <br> ";

mysql_query("SET NAMES 'GB2312'");

$mysql_command="select * from ".$table_name;
$result=mysql_query($mysql_command,$conn);
$record_count =mysql_num_rows($result);

$rec=mysql_fetch_array($result);

while($rec=mysql_fetch_array($result)){

}
echo $rec["0"];
echo $rec["1"];

?>

<p> </p>

你下面这段程序是错的:

while($rec=mysql_fetch_array($result)){

}
echo $rec["0"];
echo $rec["1"];

应该修改为:

while($rec=mysql_fetch_array($result)){
echo $rec[0];
echo $rec[1];
}

把表格写在 while里面

while($rec=mysql_fetch_array($result)){
echo '<table width="587" height="165" border="1" align="center" bgcolor="#999999">
<tr>
<td height="42">'.$rec[0].'</td>
</tr>
<tr>
<td height="115">'.$rec[2].'</td>
</tr>
</table>';

}