
正文
php批量读取数据库内容 php读取数据库内容并输出
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
php中怎样读取数据库里的多条信息
$con = mysql_connect("localhost","root","");//连接数据库
mysql_select_db("btxiazai",$con);//选择数据库
mysql_query("set names utf8");
$sql = "select * from persons order by id desc limit 2";//获取persons中的数据,并按id倒叙排列,取其中两条
$get = mysql_query($sql);//执行sql
while($result = mysql_fetch_assoc($get)){//取回数据
}
相关问答
Q1: PHP 读取多条数据库中数据
拿下面这段单独建个页面,改一下你的数据库名,表等信息试试。
table width="50%" border="0"
tr
tdID/td
tdID2/td
tdorder1/td
tdorder2/td
tdorder3/td
/tr
?php
//连接数据库
$conn=@ mysql_connect("服务器地址","用户名","密码") or die("连接数据库失败!");
mysql_select_db("数据库名",$conn) or die("连接数据库失败!");
mysql_query("set names 'GBK'");
//连接结束
//接收提交过来查询的ID
$id=$_POST["id"];
//查询数据库相关数据
$sql="select * from 数据表名 where ID2='".$id."' order by id desc";
$query=mysql_query($sql);
//循环输出
while($row=mysql_fetch_array($query)){
?
tr
td?php echo $row["ID"];?/td
td?php echo $row["ID2"];?/td
td?php echo $row["order1"];?/td
td?php echo $row["order2"];?/td
td?php echo $row["order3"];?/td
/tr
?php
}
?
/table
form name="form1" method="post" action=""
input type="text" name="id"
input type="submit" name="Submit" value="查询"
/form
Q2: PHP从数据库读取数据批量生成HTML
首先创建html文件。可以以id字段作为文件名,你如果嫌短的话,再加上time()。
如 $filename=$row[id].time."html";
然后以可写的形式打开刚刚建立的文件,把读出的数据内容存放进去。一个文件就建成了。如果建成批量的,在读取数据表的时候,把代码加到while循环里就好了。
关于php批量读取数据库内容和php读取数据库内容并输出的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。






