首页 > 编程知识 正文

php把数据库列表(php选择数据库的函数)

时间:2023-12-23 11:38:06 阅读:319282 作者:SWDP

本文目录一览:

php 列表显示数据库里的内容 怎么把数据库里最后的显示在列表的前面 就是反序显示???

select * from 表名 where 条件 order by 要排序的字段 desc

关键是:desc 倒序 默认排序是asc 正序

例如:order by id desc 按照id倒序排列

如何用php取出数据库表中一列所有数据?

很简单,用循环,你那样用只能有一条记录,建议多看看php手册,对自己有好处

while ($result= mysql_fetch_array($result, MYSQL_NUM)) {

print_r($result);

}

php 将数据库表内的数据,每1000条放入一个html

html也属于文件一种,所以取出数据还需要文件操作

?php

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

mysql_select_db("database",$con);

mysql_query("set names utf8");

$sql="select * from daschool order by id desc limit 1,1000";//limit 1,1000中的1要可变存于cookie中吧,数据库里也行,运行一次加1000

$result = mysql_query($sql);

$fp = fopen('xxx.html','r');//只写模式打开txt文档

$content="htmlhead/headbody";

while($source=mysql_fetch_assoc($result)){

$content = $content."h1".$source["title"]."/h1div".$source["article"]."/divbr/";

}

$content = $content."/body/html";

fwrite($fp,$content);

fclose($fp);

上述程序仅仅为思路,需要调试和添加,详细的文件操作可以参考

;id=77class=2

还有程序不应定要用网页打开,可以尝试php cli

;id=56class=2

PHP如何将数据库表中的某列数据一个一个循环取出并打印

一般我们为了减少数据库链接,取数据是一次取出所有想要的数据然后做循环处理,而不是一个个循环取出

$servername = "localhost";

$username = "root";

$password = "root";

$dbname = "aaaa";

 

// 创建连接

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection

if ($conn-connect_error) {

    die("连接失败: " . $conn-connect_error);

$conn-query('set names utf8');

$sql = "SELECT name FROM xiao ";//这里是查询xiao表的name列的所有数据

$result = $conn-query($sql);

 

if ($result-num_rows  0) {

    // 输出数据

    while($row = $result-fetch_assoc()) {

//print_r($row);

        echo "name: " . $row["name"]."br";//这里是循环打印

    }

} else {

    echo "没有查询到数据";

}

$conn-close();

PHP实现把mysql数据库中的表的数据导出到excel

我就贴下我当时生成EXCEL的代码,LZ可以参照,修改,然后直接访问这个PHP文件,就会自动生成EXCEL,

?php

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

header("Content-type:application/vnd.ms-excel;charset=UTF-8");

header("Content-Disposition:filename=test.xls"); //输出的表格名称

echo "IDt";echo "nametn";

//这是表格头字段 加T就是换格,加TN就是结束这一行,换行的意思

$conn = mysql_connect("localhost","用户名","密码") or die("不能连接数据库");

mysql_select_db("数据库名", $conn);

mysql_query("set names 'UTF-8'");

$sql="SQL语句";

$result=mysql_query($sql);

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

echo $row[0]."t";echo $row[1]."tn";

}

?

怎么样用php显示数据库中的表列表

function list_tables($database) 

$rs = mysql_query("SHOW TABLES FROM $database"); 

$tables = array(); 

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

$tables[] = $row[0]; 

mysql_free_result($rs); 

return $tables; 

}

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