PHP 怎么显示数据库中的数据 求源代码

如题所述

读数据库,以表格输出的示例代码:

<?php
header('Content-type:text/html;charset=utf-8');
$db = new mysqli('localhost','root','root','books');
$rows = $db->query('SELECT * FROM customers');
echo '<table border="1"><tr><td>姓名</td><td>年龄</td></tr>';
while($row = $rows->fetch_assoc()){
echo '<tr><td>'.$row['name'].'</td>';
echo '<td>'.$row['address'].'</td></tr>';
}
?追问

能说说什么代码是干啥的吗

追答

query('SELECT * FROM customers'); //用sql语句获取数据
echo '姓名年龄'; //输出表格标题
while($row = $rows->fetch_assoc()){ //输出数据库为表格内容
echo ''.$row['name'].'';
echo ''.$row['address'].'';
}
?

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-24
$dbhost = "localhost";//IP
$dbuser = "root";//账号
$dbpassword = "123456";//密码
$dbdatabase = "abc";//数据库
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
$sql = "SELECT * FROM d ";
$res = mysql_query($sql);
while($arr = mysql_fetch_row($res){ //也可以用mysql_fetch_object
echo $arr[0].$arr[1].$arr[2];//有多少个字段就输出多少
}
第2个回答  2012-05-24
查询出来 输出

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网