$urls = "192.168.0.128";//你的主機地址(一般是localhost)

成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計、網(wǎng)站制作、廣陵網(wǎng)絡(luò)推廣、成都微信小程序、廣陵網(wǎng)絡(luò)營銷、廣陵企業(yè)策劃、廣陵品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供廣陵建站搭建服務(wù),24小時服務(wù)熱線:18980820575,官方網(wǎng)址:chinadenli.net
$user = "root";//數(shù)據(jù)庫用戶名
$password = "111111";//數(shù)據(jù)庫密碼
$con = mysqli_connect($urls,$user,$password);//mysql數(shù)據(jù)庫連接
mysqli_select_db($con,"le_test");//第二個參數(shù)為數(shù)據(jù)庫名稱
mysqli_query($con,"select click_num from fstk_zhi_click where id0");//查詢所有click_num
mysqli_close($con);//關(guān)閉連接
試編寫代碼如下:
?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();
?
$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)里取出。
分享名稱:php從數(shù)據(jù)庫中取出數(shù)據(jù),php獲取數(shù)據(jù)庫的某條信息
本文來源:http://chinadenli.net/article41/dsieehd.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、標簽優(yōu)化、做網(wǎng)站、移動網(wǎng)站建設(shè)、品牌網(wǎng)站制作、小程序開發(fā)
聲明:本網(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)