1、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之 mysql_result()

成都創(chuàng)新互聯(lián)是專業(yè)的聶榮網(wǎng)站建設公司,聶榮接單;提供網(wǎng)站設計、成都做網(wǎng)站,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行聶榮網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
mixed mysql_result(resource result_set, int row [,mixed field])
從result_set 的指定row 中獲取一個field 的數(shù)據(jù). 簡單但是效率低.
舉例:
$link1 = @mysql_connect("server1",
"webuser", "password")
or die("Could not connect
to mysql server!");
@mysql_select_db("company")
or die("Could not select database!");
$query = "select id, name
from product order by name";
$result = mysql_query($query);
$id = mysql_result($result, 0, "id");
$name = mysql_result($result, 0, "name");
mysql_close();
注意,上述代碼只是輸出結(jié)果集中的第一條數(shù)據(jù)的字段值,如果要輸出所有記錄,需要循環(huán)處理.
for ($i = 0; $i = mysql_num_rows($result); $i++)
{
$id = mysql_result($result, 0, "id");
$name = mysql_result($result, 0, "name");
echo "Product: $name ($id)";
}
注意,如果查詢字段名是別名,則mysql_result中就使用別名.
2、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_row()
array mysql_fetch_row(resource result_set)
從result_set中獲取整行,把數(shù)據(jù)放入數(shù)組中.
舉例(注意和list 的巧妙配合):
$query = "select id,
name from product order by name";
$result = mysql_query($query);
while(list($id, $name)
= mysql_fetch_row($result)) {
echo "Product: $name ($id)";
}
3、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_array()
array mysql_fetch_array(resource result_set [,int result_type])
mysql_fetch_row()的增強版.
將result_set的每一行獲取為一個關聯(lián)數(shù)組或/和數(shù)值索引數(shù)組.
默認獲取兩種數(shù)組,result_type可以設置:
MYSQL_ASSOC:返回關聯(lián)數(shù)組,字段名=字段值
MYSQL_NUM:返回數(shù)值索引數(shù)組.
MYSQL_BOTH:獲取兩種數(shù)組.因此每個字段可以按索引偏移引用,也可以按字段名引用.
舉例:
$query = "select id,
name from product order by name";
$result = mysql_query($query);
while($row = mysql_fetch_array
($result, MYSQL_BOTH)) {
$name = $row['name'];
//或者 $name = $row[1];
$name = $row['id'];
//或者 $name = $row[0];
echo "Product: $name ($id)";
}
4、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_assoc()
array mysql_fetch_assoc(resource result_set)
相當于 mysql_fetch_array($result, MYSQL_ASSOC)
5、PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)之mysql_fetch_object()
object mysql_fetch_object(resource result_set)
和mysql_fetch_array()功能一樣,不過返回的不是數(shù)組,而是一個對象.
舉例:
$query = "select id, name
from product order by name";
$result = mysql_query($query);
while($row = mysql_fetch_object
($result)) {
$name = $row-name;
$name = $row-id;
echo "Product: $name ($id)";
}
以上這些函數(shù)就是PHP獲取顯示數(shù)據(jù)庫數(shù)據(jù)函數(shù)的全部總結(jié)。
?php
//設置連接
$DBserver
=
"localhost";
$DBname
=
"數(shù)據(jù)庫";
$DBuser
=
"賬號";
$DBpassword
=
"密碼";
$con
=
mysql_connect("localhost","賬號","密碼");
mysql_select_db("數(shù)據(jù)庫");
$contents
=
file_get_contents($url);
//$contents就是網(wǎng)頁內(nèi)容,$url就是鏈接
$contents
=
mysql_real_escape_string($contents);
//轉(zhuǎn)義,不用可以不要
$SQL="
INSERT
INTO
數(shù)據(jù)庫表(數(shù)據(jù)字段)
VALUES('{$contents}')";
mysql_query($SQL)
or
die(mysql_error());
?
你這個想法很好,但是實現(xiàn)起來很麻煩,首先你需要淘寶對你開放API接口才行,然后寫代碼有事一個難事,不過我知道有一個軟件是可以實現(xiàn)的,甩手掌柜,只需要綁定你的淘寶賬號就可以,因為他們一個公司,和淘寶合作,淘寶對其開放API,然后一個團隊寫代碼,所以是可以實現(xiàn)的。不光可以自動下載訂單,還可以輕松管理商品,打印發(fā)貨單,進銷存管理等等!
在html中調(diào)用php內(nèi)容,可以用script src="friendlinks.php"/script然后在friendlinks.php中調(diào)取數(shù)據(jù)庫數(shù)據(jù)。并輸出適當?shù)膆tml,或者輸出xml、json都可以,只是圖簡單的話,只要輸出html就行了。
strip_tags是PHP自帶的過濾HTML標簽的函數(shù)。
$row=mb_substr(htmlspecialchars(strip_tags($latestnews['content'])),0,26,'UTF-8')
如果想把script/script之間的也去掉,只能正則了:
$str = preg_replace("|script.*.*/script|Usi", '', $str);
大概的基本流程如下:
連接數(shù)據(jù)庫,再加一個判斷。
選擇數(shù)據(jù)庫
讀取表
輸出表中數(shù)據(jù)
下面是代碼:
?php
$con = mysql_connect("localhost","root","abc123");
/* localhost 是服務器 root 是用戶名?abc123 是密碼*/?
if (!$con)
{
die("數(shù)據(jù)庫服務器連接失敗");
}
/*?這就是一個邏輯非判斷,如果錯誤就輸出括號里的字符串 */?
@mysql_select_db("a",?$con);?
/*?選擇mysql服務器里的一個數(shù)據(jù)庫,假設你的數(shù)據(jù)庫名為?a*/
$sql?=?"SELECT?*?FROM qq";?
/* 定義變量sql,?"SELECT?*?FROM?qq" 是SQL指令,表示選取表qq中的數(shù)據(jù)?*/
$result = mysql_query($sql); //執(zhí)行SQL語句,獲得結(jié)果集
/*下面就是選擇性的輸出打印了,由于不清楚你的具體情況給你個表格打印吧*/
//打印表格?
echo "table border=1";?
while( $row = mysql_fetch_array($result) )
/*逐行獲取結(jié)果集中的記錄,得到數(shù)組row?*/
{ ?
/*數(shù)組row的下標對應著數(shù)據(jù)庫中的字段值?*/
$id = $row['id'];?
$name = $row['name'];?
$sex = $row['sex'];?
echo "tr";?
echo "td$id/td";?
echo "td$name/td";?
echo "td$sex/td";?
echo "/tr";?
}?
echo "table /";
?
如果你的switch是表頭,就定義這個表頭字段,然后輸出。
本文名稱:php自動抓取數(shù)據(jù)庫,php實時讀取數(shù)據(jù)庫
轉(zhuǎn)載源于:http://chinadenli.net/article9/dsgcpoh.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、軟件開發(fā)、外貿(mào)網(wǎng)站建設、網(wǎng)站設計公司、網(wǎng)站營銷、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)