php數(shù)據(jù)庫提取 php讀取數(shù)據(jù)庫內(nèi)容并輸出

php如何取數(shù)據(jù)庫中內(nèi)容

試編寫代碼如下:

創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,提供成都做網(wǎng)站、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);可快速的進行網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,是專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

?php

//從數(shù)據(jù)庫根據(jù)?id?獲取顏色

function?getColor($db,?$id)

{

if?($result?=?$db-query("SELECT?*?FROM?color?where?id='"?.?$id?.?"'"))

{

$row?=?$result-fetch_assoc();

return?$row['color'];

}

return?'#000000';

}

$mysqli?=?new?mysqli("localhost",?"test",?"test",?"room");

if?($mysqli-connect_error)?{

printf("數(shù)據(jù)庫連接錯誤:?%s\n",?mysqli_connect_error());

exit();

}

?

table?border="1"?cellspacing="0"

tr

td?bgcolor="?php?echo?getColor($mysqli,'1')?"1/td

/tr

tr

td?bgcolor="?php?echo?getColor($mysqli,'2')?"2/td

/tr

tr

td?bgcolor="?php?echo?getColor($mysqli,'3')?"3/td

/tr

/table

?php

$mysqli-close();

?

php如何從數(shù)據(jù)庫中提取數(shù)據(jù)并輸出成分列數(shù)據(jù)

可以使用pdo鏈接數(shù)據(jù)庫讀取數(shù)據(jù):

?php

//構(gòu)造PDO連接

$dbh?=?"mysql:host=localhost;dbname=test";

$db?=?new?PDO($dbh,?'root',?'root123');

$db-query("set?character?set?'gbk'");

//查詢數(shù)據(jù)

$sql?=?"SELECT?*?FROM?info";

$sth?=?$db-query($sql);

while($row?=?$sth-fetch()){

echo?"用戶業(yè)務(wù)類型:".$row['leixing']."br?/";

echo?"業(yè)務(wù)編號:".$row['bianhao']."br?/";

echo?"注冊序號:".$row['xuhao']."br?/br?/";

}

$db?=?null;

?

大致流程就是這樣,

具體的輸出樣式需要自己定義

php如何獲取數(shù)據(jù)庫信息

代碼如下:?View

Code

PHP

include("conn.php");//調(diào)用數(shù)據(jù)庫連接文件

echo

"table

width=572

height=56

border=0

cellspacing=1

";

//創(chuàng)建html表格

echo

"tr

bgcolor=#9999FF";

echo

"th

width=33

scope=colid/th";

echo

"th

width=100

scope=coluser_name/th

";

echo

"th

width=100

scope=coluser_pass/th

";

echo

"th

width=100

scope=colstaus/th";

echo

"th

width=100

scope=colinsert_time/th";

echo

"/tr";

$SQL

=

"select

*

from

user_info";

$query

=

mysql_query($SQL);

//SQL查詢語句

while

($row

=

mysql_fetch_array($query)){

//使用while循環(huán)mysql_fetch_array()并將數(shù)據(jù)返回數(shù)組

echo

"tr

onmouseout=this.style.backgroundColor=''

onMouseOver=this.style.backgroundColor='#99CC33'

bgcolor=#CCCCCC";

echo

"td$row[0]/td";

//輸出數(shù)組中數(shù)據(jù)

echo

"td$row[1]/td";

echo

"td$row[2]/td";

echo

"td$row[3]/td";

echo

"td$row[4]/td";

echo

"/tr";

}

echo

"/table";輸出記錄截圖

php怎么從其他的數(shù)據(jù)庫里面取數(shù)據(jù)

$con=mysql_connect('localhost','root','');//數(shù)據(jù)庫信息

mysql_select_db('shop');//數(shù)據(jù)庫名

mysql_query("set?names?utf8");//設(shè)置字符集編碼

$sql="select?goods_name,goods_number,shop_price?from?goods";//查詢語句

$res=mysql_query($sql);//執(zhí)行查詢

while($row=mysql_fetch_assoc($res)){

$rows[]=$row;//接受結(jié)果集

}

//遍歷數(shù)組

foreach($rows?as?$key=$v){

echo?$v['goods_name']."---".$v['goods_number']."---".$v['shop_price']."";

}

布局可以自己寫的。數(shù)據(jù)從foreach循環(huán)里取出。

網(wǎng)站題目:php數(shù)據(jù)庫提取 php讀取數(shù)據(jù)庫內(nèi)容并輸出
新聞來源:http://muchs.cn/article36/docoppg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、定制網(wǎng)站面包屑導(dǎo)航動態(tài)網(wǎng)站、網(wǎng)站策劃、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)