php mysql数据输出页面_PHP如何查询MySQL数据页面输出内容

2019独角兽企业重金招聘Python工程师标准>>>

6936d1565ae689371725cdb5fc51c415.png

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

/**

* mysql connection configure

* 2016-04-09

* Ron

*/

$ychat_host = "localhost";

$ychat_username = "root";

$ychat_password = "";

$ychat_database = "talk";

$con = mysql_connect($ychat_host,$ychat_username,$ychat_password) or die ("connection MySQL failed!");

//select database

mysql_select_db($ychat_database,$con);

//sql

$sql = "select id,username,password,sex,address,country from userinfo ";

//set encode

mysql_query("set names utf8");

//query results

$result = mysql_query($sql) or die ("query failed! "+mysql_error);

//count

$count = mysql_num_rows($result);

// number of rows

$rows = mysql_affected_rows($con);

// Number of colums

$colums = mysql_num_fields($result);

if($count==0){

echo "no result!";

}else{

echo "total:".$count;

echo "";

echo "

";

for($i = 0;$i < $colums; $i++){

$fieldName = mysql_field_name($result, $i);

echo "$fieldName";

}

echo "";

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

echo "

";

for($i=0; $i$row[$i]";

}

echo "";

}

echo "";

}

// release result set

mysql_free_result($result);

//close connection

mysql_close($con);

?>

ec57c32d17ee9d2795e29066b4c5a29a.png

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

/**

* mysel connection configure

* 2016-04-09

* Ron

*/

$ychat_host = "localhost";

$ychat_username = "root";

$ychat_password = "";

$ychat_database = "talk";

$con = mysql_connect($ychat_host,$ychat_username,$ychat_password) or die ("connection MySQL failed!");

//select database

mysql_select_db($ychat_database,$con);

//sql

$sql = "select id,username,password,sex,address,country from userinfo";

//set encode

mysql_query("set names utf8");

//query results

$result = mysql_query($sql) or die ("query failed! "+mysql_error);

//count

$count = mysql_num_rows($result);

if($count==0){

echo "no result!";

}else{

echo "";

echo "

";

echo "id用户名性别地址国家";

echo "";

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

$id= $userinfo["id"];

$name= $userinfo["username"];

$sex= $userinfo["sex"];

$address= $userinfo["address"];

$country= $userinfo["country"];

echo "

";

echo "$id$name$sex$address$country";

echo "";

}

echo "";

}

// release result set

mysql_free_result($result);

//close connection

mysql_close($con);

?>

9bedb50ddc2590b569d6b5f111c3146e.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值