1、從數(shù)據(jù)庫查詢兩個(gè)記錄
創(chuàng)新互聯(lián)專注于企業(yè)網(wǎng)絡(luò)營銷推廣、網(wǎng)站重做改版、浙江網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場景定制、商城開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為浙江等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
$res -- aa表的全部結(jié)果集。select id,shuju from aa
$max -- aa表中shuju字段的最大值。select max(shuju) from aa
2、foreach()循環(huán)結(jié)果集
foreach($res as $item) {
//每一項(xiàng)除以查詢出來的最大值,執(zhí)行insert bb表操作
insert into bb (id,shuju,deifen) values ($item['id'],$item['shuju'],$item['shuju']/$max);
}
如果不是特別要求用循環(huán)處理 推薦nietiezheng的答案。這個(gè)簡單 快捷。
insert into bb (id,shuju,deifen) select id,shuju,shuju/$max from aa
可以使用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ù)編號(hào):".$row['bianhao']."br?/";
echo?"注冊(cè)序號(hào):".$row['xuhao']."br?/br?/";
}
$db?=?null;
?
大致流程就是這樣,
具體的輸出樣式需要自己定義
獲取ppq數(shù)據(jù)庫的所有表名的代碼:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("數(shù)據(jù)庫系統(tǒng)連接失??!");
$result=mysql_list_tables($dbname);
if(!$result)
die("數(shù)據(jù)庫連接失??!");
while($row=mysql_fetch_row($result))
{
echo
$row[0]."
";
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
--
列出
MySQL
數(shù)據(jù)庫中的表
說明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個(gè)數(shù)據(jù)庫名并返回和
mysql_query()
函數(shù)很相似的一個(gè)結(jié)果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個(gè)數(shù)組,數(shù)組的第0列就是數(shù)組名,當(dāng)獲取不到時(shí)
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
本文名稱:php提取數(shù)據(jù)庫數(shù)據(jù)以后,php隨機(jī)取數(shù)據(jù)庫內(nèi)容
轉(zhuǎn)載來源:http://m.rwnh.cn/article0/phjooo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、微信公眾號(hào)、網(wǎng)站導(dǎo)航、、品牌網(wǎng)站制作、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)