php 从数据库里面取出数据 生成一个 html表格 有多少数据生成多少 怎么写php

php 从数据库里面取出数据 生成一个 html表格 有多少数据生成多少 怎么写php,第1张

很简单的,

1首先你连接数据库,2然后查询数据库里面所有的数据,3查询出来的数据放在一个<table>里面

例如:

<php mysql_connect("localhost","root","密码","数据库名称");

$_sql="select from 表名";

mysql_query("set names utf8");//编码设置为utf8

$query=mysql_query($_sql);

echo "<table>";

while($row=mysql_fetch_array($query))

{

//从数据库查询出来的字段

$数据1=$row["字段1"];

$数据2=$row["字段2"];

$数据3=$row["字段3"];

//将数据放到html的表格

echo "<tr><td>$数据1</td><td>$数据2</td><td>$数据3</td></tr>";

}

echo "</table>";

>

这个是取出数据生成一个html表格,希望你能采纳我,因为我马上要升级了,谢谢!

<php

$sql = "SELECT name FROM user WHERE ID=1 LIMIT 0,1";

$result = mysql_query($sql);

$rs = mysql_result($result,0);

>

<php

//设置编码格式

header("Content-type:text/html;charset=utf-8");

//链接数据库

$conn = mysql_connect("localhost","root","");

//选择要 *** 作的数据库

mysql_select_db('act1',$conn);

//设置 *** 作数据库编码格式

mysql_query("set names utf8");

//执行查询 *** 作

$re= mysql_query("select user_name,phone from user");

>

<table border='1px'>

<!-- 表格头部 -->

<tr>

<td>用户名</td><td>电话</td>

</tr>

<php

//每循环一次,取一行数据记录显示在一行中

while($row=@mysql_fetch_row($re)){

>

<tr>

<td><php echo $row[0];></td><td><php echo $row[1];></td>

</tr>

<php

}    

>

</table>

显示结果如下:

先配置数据库------连接数据库--------选择数据库--------填写检索表-------输出检索内容

第一种解决方法:

一、配置一下数据库:

define("DB_HOST","localhost");//数据库地址,一般为localhost

define("DB_USER","root");//数据库用户名

define("DB_PSW","");//数据库密码

define("DB_DB","databasename");//需要 *** 作的数据库

二、连接数据库:

$conn = mysql_connect(DB_HOST,DB_USER,DB_PSW) or die

三、选择数据库:

mysql_select_db(DB_DB,$conn) or die

四、检索表:(填写tablename)

$result = mysql_query("select from tablename") or die

五、输出检索的内容:

while ($row = mysql_fetch_row($result)){foreach($row as $data){    echo $data' ';}    echo '<br。

$conn=mysql_connect(localhost,root,root) or die("could not connect mysql");

mysql_select_db(数据库,$conn);

$query="SELECT FROM 表";

$result=mysql_query($query);

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

arr[]=[$array[1],$array[2]],[$array[2],$array[3]],[$array[3],$array[4]];

}

你好,我想到了两种方法:

第一种:可以使用js脚本调用php,PHP查询后返回给js,js再把内容替换到某个idv

第二种:直接用php来做,不需要js和html,php先输出html头,再查询sql,并输出,再输出html别的内容或者结束语句

以上就是关于php 从数据库里面取出数据 生成一个 html表格 有多少数据生成多少 怎么写php全部的内容,包括:php 从数据库里面取出数据 生成一个 html表格 有多少数据生成多少 怎么写php、如何在php中获取数据库中字段值、php读取mysql,如何以表格显示数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9800202.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存