首页 > 编程知识 正文

php如何展示数据表,如何用php输出有内容表格

时间:2023-12-27 22:27:59 阅读:327099 作者:MFAF

本文目录一览:

php怎么把数据表横向展示

这个很简单的,先说个比较容易理解的方法

将while循环方式修改下即可。

echo('trtdname/td');

while($row = mysqli_fetch_array($result)){

echo('td'.$row['name'].'/td');

}

echo('/tr');

echo('trtdgender/td');

while($row = mysqli_fetch_array($result)){

echo('td'.$row['gender'].'/td');

}

echo('/tr');

echo('trtdage/td');

while($row = mysqli_fetch_array($result)){

echo('td'.$row['age'].'/td');

}

echo('/tr');

怎么用php显示mysql 数据表数据

html

head

title浏览表中记录/title

/head

body

center

?php

$db_host=localhost; //MYSQL服务器名

$db_user=root; //MYSQL用户名

$db_pass=""; //MYSQL用户对应密码

$db_name="test"; //要操作的数据库

//使用mysql_connect()函数对服务器进行连接,如果出错返回相应信息

$link=mysql_connect($db_host,$db_user,$db_pass)or die("不能连接到服务器".mysql_error());

mysql_select_db($db_name,$link); //选择相应的数据库,这里选择test库

$sql="select * from test1"; //先执行SQL语句显示所有记录以与插入后相比较

$result=mysql_query($sql,$link); //使用mysql_query()发送SQL请求

echo "当前表中的记录有:";

echo "table border=1"; //使用表格格式化数据

echo "trtdID/tdtd姓名/tdtd邮箱/tdtd电话/tdtd地址/td/tr";

while($row=mysql_fetch_array($result)) //遍历SQL语句执行结果把值赋给数组

{

echo "tr";

echo "td".$row[id]."/td"; //显示ID

echo "td".$row[name]." /td"; //显示姓名

echo "td".$row[mail]." /td"; //显示邮箱

echo "td".$row[phone]." /td"; //显示电话

echo "td".$row[address]." /td"; //显示地址

echo "/tr";

}

echo "/table";

?

/center

/body

/html

php如何查询数据库表中的数据并显示

这个简单啊!

首页做个前台输入姓名和会员卡信息的页面,我做个简单的页面给你看

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "

html xmlns="

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

title会员查询系统/title

/head

body

form id="form1" name="form1" method="post" action="test.php"

  p

    label for="name"/label

    input type="text" name="name" id="name" /

  /p

  p

    label for="vipid"/label

    input type="text" name="vipid" id="vipid" /

  /p

  p

    input type="submit" name="button" id="button" value="查询" /

  /p

/form

/body

/html

然后我给你一个test.php的文件代码:

?php

$name    =    trim($_POST['name']);

$vipid    =    trim($_POST['vipid']);

$con = mysql_connect("127.0.0.1","数据库用户名","数据库密码");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

$a    =    mysql_select_db("数据库名字", $con);

$sql    =    "select * from kh_customer where name = '$name' and vipid = '$vipid'";

$result = mysql_query($sql);

while($row = mysql_fetch_array($result))

  {

  echo $row['name'] . " " . $row['data'];

  echo "br /";

  }

mysql_close($con);

?

页面美化自己去搞!只能帮你这么多了

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。