?php

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比潮陽網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式潮陽網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務覆蓋潮陽地區(qū)。費用合理售后完善,十多年實體公司更值得信賴。
/**
*
@param
string
$url
地址url
*
@return
$array
返回url對應的id
*/
function
getid($url){
//連接數(shù)據(jù)庫
mysql_connect('localhost','root','user')
or
die('數(shù)據(jù)庫鏈接失敗');
//不清楚數(shù)據(jù)庫名稱,這里用dbname代表數(shù)據(jù)庫名稱。需要替換為實際的數(shù)據(jù)庫名稱
mysql_select_db('dbname');
mysql_query('set
names
utf8');//如果頁面編碼是utf-8的。這里設(shè)置查詢的編碼為utf-8
$sql
=
"select
`id`
from
`visitor`
where
`file`='{$url}'";
$result
=
mysql_query($sql);
//不清楚url是不是會重復,這里循環(huán)可以保證得到所有的id
while($row
=
mysql_fetch_assoc($result)){
$id[]
=
$row['id']
}
//如果url不會重復則使用$id[0],如果會重復則循環(huán)$id就可以得到每個id了。
return
$id;
}
因為你查詢數(shù)據(jù)庫返回數(shù)組時用的是返回包含關(guān)聯(lián)和數(shù)字索引的數(shù)組(MYSQL_BOTH)
建議使用mysql_fetch_assoc來遍歷結(jié)果集
首先你要確認數(shù)據(jù)庫里面存在tb_id為1和4的記錄。
其次你輸出$array[tb1.tb_content]是不對的,兩個字段都會叫做$array[tb_content],你可以用$array[0]、$array[1]來輸出,或者語句里面定義別名:
$string = "select tb1.tb_content content1, tb2.tb_content content2 from tb as tb1, tb as tb2 where tb1.tb_id =1 and tb2.tb_id=4";
這樣就可以輸出$array[content1]、$array[content2]
另外最好程序中隨時檢測并輸出錯誤信息,我修改語句如下:
if ($query = mysql_query($string, $db_connection)){
...while ...
}else echo "執(zhí)行 $string 錯誤:".mysql_error();
網(wǎng)頁標題:php數(shù)據(jù)庫查詢兩次 php查詢數(shù)據(jù)庫并顯示
網(wǎng)站路徑:http://www.chinadenli.net/article36/dodohpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、App設(shè)計、靜態(tài)網(wǎng)站、自適應網(wǎ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)