为了账号安全,请及时绑定邮箱和手机立即绑定

为什么运行后只能输出一行结果,我是想输出满足age=20的全部结果的。 代码哪里写错了?

为什么运行后只能输出一行结果,我是想输出满足age=20的全部结果的。 代码哪里写错了?

Smart猫小萌 2023-03-06 18:14:47
数据库中有一个表test为:id name age $sql="select * from test where age=20";$result=mysql_query($sql);echo "<table border='1' cellspacing=0px><tr><th>id</th><th>name</th><th>age</th></tr>";while ($row=mysql_fetch_array($result)) {echo "<tr>";echo "<td>".$row['id']."</td>";echo "<td>".$row['name']."</td>";echo "<td>".$row['age']."</td>";echo "</tr>";}echo "</table>";
查看完整描述

1 回答

?
守着星空守着你

TA贡献1799条经验 获得超8个赞

你使用的函数就是单条的。请换成mysql_fetch_field


<?php$con = mysql_connect("localhost""hello""321");if (!$con)  {  die('Could not connect: ' . mysql_error());  } $db_selected = mysql_select_db("test_db",$con); $sql "SELECT * from Person";$result = mysql_query($sql,$con); while ($property = mysql_fetch_field($result))  {  echo "Field name: " $property->name . "<br />";  echo "Table name: " $property->table . "<br />";  echo "Default value: " $property->def . "<br />";  echo "Max length: " $property->max_length . "<br />";  echo "Not NULL: " $property->not_null . "<br />"  echo "Primary Key: " $property->primary_key . "<br />";  echo "Unique Key: " $property->unique_key . "<br />"  echo "Mutliple Key: " $property->multiple_key . "<br />";  echo "Numeric Field: " $property->numeric . "<br />";  echo "BLOB: " $property->blob . "<br />";  echo "Field Type: " $property->type . "<br />";  echo "Unsigned: " $property->unsigned . "<br />";  echo "Zero-filled: " $property->zerofill . "<br /><br />"  } mysql_close($con);?>


查看完整回答
反对 回复 2023-03-08
  • 1 回答
  • 0 关注
  • 100 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号