脚本宝典收集整理的这篇文章主要介绍了php – 从sql表创建HTML表,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
对不起,如果这是一个非常简单的问题,我对PHP和sql知之甚少.
<html> <head> <tITle>Last 5 Results</title> </head> <body> <?PHP $connect = MysqL_connect("localhost","root","root"); if (!$connect) { die(MysqL_error()); } MysqL_select_db("apploymentdevs"); $results = MysqL_query("SELECT * From demo"); while($row = MysqL_fetch_array($results)) { echo $row['Name'] . "</br>"; ?> </body> </html>
此外,您应该将连接逻辑和查询移动到进程的开头,从而避免在加载页面时出现错误并显示比MysqL_error更准确的错误.
编辑:如果您的ID正在递增,那么您可以添加ORDER BY子句,
更改:SELECT * From demo LIMIT 10
to:SELECT * FROM demo LIMIT 10 ORDER BY id
<html> <head> <title>Last 10 Results</title> </head> <body> <table> <thead> <tr> <td>Id</td> <td>Name</td> </tr> </thead> <tbody> <?PHP $connect = MysqL_connect("localhost","root"); if (!$connect) { die(MysqL_error()); } MysqL_select_db("apploymentdevs"); $results = MysqL_query("SELECT * FROM demo LIMIT 10"); while($row = MysqL_fetch_array($results)) { ?> <tr> <td><?PHP echo $row['Id']?></td> <td><?PHP echo $row['Name']?></td> </tr> <?PHP } ?> </tbody> </table> </body> </html>
以上是脚本宝典为你收集整理的php – 从sql表创建HTML表全部内容,希望文章能够帮你解决php – 从sql表创建HTML表所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。