?php
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供興業(yè)網(wǎng)站建設(shè)、興業(yè)做網(wǎng)站、興業(yè)網(wǎng)站設(shè)計(jì)、興業(yè)網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、興業(yè)企業(yè)網(wǎng)站模板建站服務(wù),10多年興業(yè)做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
/**
*
@param
string
$url
地址url
*
@return
$array
返回url對(duì)應(yīng)的id
*/
function
getid($url){
//連接數(shù)據(jù)庫(kù)
mysql_connect('localhost','root','user')
or
die('數(shù)據(jù)庫(kù)鏈接失敗');
//不清楚數(shù)據(jù)庫(kù)名稱,這里用dbname代表數(shù)據(jù)庫(kù)名稱。需要替換為實(shí)際的數(shù)據(jù)庫(kù)名稱
mysql_select_db('dbname');
mysql_query('set
names
utf8');//如果頁(yè)面編碼是utf-8的。這里設(shè)置查詢的編碼為utf-8
$sql
=
"select
`id`
from
`visitor`
where
`file`='{$url}'";
$result
=
mysql_query($sql);
//不清楚url是不是會(huì)重復(fù),這里循環(huán)可以保證得到所有的id
while($row
=
mysql_fetch_assoc($result)){
$id[]
=
$row['id']
}
//如果url不會(huì)重復(fù)則使用$id[0],如果會(huì)重復(fù)則循環(huán)$id就可以得到每個(gè)id了。
return
$id;
}
您好,用遞歸的方法。
?php
global $str;
$str = getson(0); //getson里面的參數(shù)是,上級(jí)目錄的id
echo $str;
function getson($fatherid)
{
$str = $str . "ul";
$sql="Select * From 表 Where 上級(jí)欄目ID=$fatherid";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$str = $str . "li" . $row[欄目名稱] . "/li" . getson($row[該欄目的ID]);
}
return $str."/ul";
}
?
thinkPHP 查詢數(shù)據(jù)庫(kù)中id最大的一條數(shù)據(jù)操作如下:
先給數(shù)據(jù)庫(kù)中的這個(gè)字段(sort)分組 再降序排列, 取第1條。
通過步驟1 獲取了 sort值為最大的數(shù)據(jù), 然后在 通過 where sort ='步驟1取的值'。
查詢最大ID,select max(id) from table。
查詢最大ID的記錄 select * from table where id = (select max(id) from table)
或者select * from table t where ?not exists (select 1 from table t1 where t1.id t.id)
本文標(biāo)題:phpid查詢數(shù)據(jù)庫(kù) php獲取數(shù)據(jù)庫(kù)用戶id
本文網(wǎng)址:http://muchs.cn/article2/ddijioc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、軟件開發(fā)、網(wǎng)站導(dǎo)航、自適應(yīng)網(wǎng)站、服務(wù)器托管、營(yíng)銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)