這個(gè)簡(jiǎn)單啊!

我們提供的服務(wù)有:成都網(wǎng)站制作、做網(wǎng)站、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、魏縣ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的魏縣網(wǎng)站制作公司
首頁做個(gè)前臺(tái)輸入姓名和會(huì)員卡信息的頁面,我做個(gè)簡(jiǎn)單的頁面給你看
!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"
html?xmlns="
head
meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/
title會(huì)員查詢系統(tǒng)/title
/head
body
form?id="form1"?name="form1"?method="post"?action="test.php"
p
label?for="name"/label
input?type="text"?name="name"?id="name"?/
/p
p
label?for="vipid"/label
input?type="text"?name="vipid"?id="vipid"?/
/p
p
input?type="submit"?name="button"?id="button"?value="查詢"?/
/p
/form
/body
/html
然后我給你一個(gè)test.php的文件代碼:
?php
$name????=????trim($_POST['name']);
$vipid????=????trim($_POST['vipid']);
$con?=?mysql_connect("127.0.0.1","數(shù)據(jù)庫(kù)用戶名","數(shù)據(jù)庫(kù)密碼");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
$a????=????mysql_select_db("數(shù)據(jù)庫(kù)名字",?$con);
$sql????=????"select?*?from?kh_customer?where?name?=?'$name'?and?vipid?=?'$vipid'";
$result?=?mysql_query($sql);
while($row?=?mysql_fetch_array($result))
{
echo?$row['name']?.?"?"?.?$row['data'];
echo?"br?/";
}
mysql_close($con);
?
頁面美化自己去搞!只能幫你這么多了
你是使用php來讀取數(shù)據(jù)庫(kù)的嗎?
如果是的話,那么,你把下面的這個(gè)類保存成一個(gè)文件:
————————————————————
?php
/**
* IP 地理位置查詢類
*
* @author joyphper
* @version 1.0
* @copyright 2010 joyphper.net
*/
class ip_area {
/**
*
*
* @var resource
*/
private $fp;//IP庫(kù)文件指針 resource
private $firstip;//第一條IP記錄的偏移地址 int
private $lastip;//最后一條IP記錄的偏移地址 int
private $totalip;//IP記錄的總條數(shù)(不包含版本信息記錄) int
/**
* 構(gòu)造函數(shù),打開 QQWry.Dat 文件并初始化類中的信息
*
* @param string $filename
* @return IpLocation
*/
public function __construct($filename = "data/ipdb.Dat") {//////////////////////////////////////////////這里注意,根據(jù)你的數(shù)據(jù)庫(kù)存放位置不同,把這個(gè)數(shù)據(jù)庫(kù)進(jìn)行引入。
$this-fp = 0;
if (($this-fp = fopen($filename, 'rb')) !== false) {
$this-firstip = $this-getlong();
$this-lastip = $this-getlong();
$this-totalip = ($this-lastip - $this-firstip) / 7;//注冊(cè)析構(gòu)函數(shù),使其在程序執(zhí)行結(jié)束時(shí)執(zhí)行
register_shutdown_function(array($this, '__destruct'));
}
}
/**
* 析構(gòu)函數(shù),用于在頁面執(zhí)行結(jié)束后自動(dòng)關(guān)閉打開的文件。
*
*/
public function __destruct() {
if ($this-fp) {
fclose($this-fp);
}
$this-fp = 0;
}
/**
* 返回讀取的長(zhǎng)整型數(shù)
*
* @access private
* @return int
*/
private function getlong() {//將讀取的little-endian編碼的4個(gè)字節(jié)轉(zhuǎn)化為長(zhǎng)整型數(shù)
$result = unpack('Vlong', fread($this-fp, 4));
return $result['long'];
}
/**
* 返回讀取的3個(gè)字節(jié)的長(zhǎng)整型數(shù)
*
* @access private
* @return int
*/
private function getlong3() {//將讀取的little-endian編碼的3個(gè)字節(jié)轉(zhuǎn)化為長(zhǎng)整型數(shù)
$result = unpack('Vlong', fread($this-fp, 3).chr(0));
return $result['long'];
}
/**
* 返回壓縮后可進(jìn)行比較的IP地址
*
* @access private
* @param string $ip
* @return string
*/
private function packip($ip) {// 將IP地址轉(zhuǎn)化為長(zhǎng)整型數(shù),如果在PHP5中,IP地址錯(cuò)誤,則返回False,// 這時(shí)intval將Flase轉(zhuǎn)化為整數(shù)-1,之后壓縮成big-endian編碼的字符串
return pack('N', intval(ip2long($ip)));
}
/**
* 返回讀取的字符串
*
* @access private
* @param string $data
* @return string
*/
private function getstring($data = "") {
$char = fread($this-fp, 1);
while (ord($char) 0) {// 字符串按照C格式保存,以\0結(jié)束
$data .= $char;// 將讀取的字符連接到給定字符串之后
$char = fread($this-fp, 1);
}
return $data;
}
/**
* 返回地區(qū)信息
*
* @access private
* @return string
*/
private function getarea() {
$byte = fread($this-fp, 1);// 標(biāo)志字節(jié)
switch (ord($byte)) {
case 0:// 沒有區(qū)域信息
$area = "";
break;
case 1:
case 2:// 標(biāo)志字節(jié)為1或2,表示區(qū)域信息被重定向
fseek($this-fp, $this-getlong3());
$area = $this-getstring();
break;
default:// 否則,表示區(qū)域信息沒有被重定向
$area = $this-getstring($byte);
break;
}
return $area;
}
/**
* 根據(jù)所給 IP 地址或域名返回所在地區(qū)信息
*
* @access public
* @param string $ip
* @return array
*/
public function get($ip) {
if (!$this-fp) return null;// 如果數(shù)據(jù)文件沒有被正確打開,則直接返回空
$location['ip'] = gethostbyname($ip); // 將輸入的域名轉(zhuǎn)化為IP地址
$ip = $this-packip($location['ip']); // 將輸入的IP地址轉(zhuǎn)化為可比較的IP地址
// 不合法的IP地址會(huì)被轉(zhuǎn)化為255.255.255.255// 對(duì)分搜索
$l = 0;// 搜索的下邊界
$u = $this-totalip;// 搜索的上邊界
$findip = $this-lastip;// 如果沒有找到就返回最后一條IP記錄(QQWry.Dat的版本信息)
while ($l = $u) {// 當(dāng)上邊界小于下邊界時(shí),查找失敗
$i = floor(($l + $u) / 2); // 計(jì)算近似中間記錄
fseek($this-fp, $this-firstip + $i * 7);
$beginip = strrev(fread($this-fp, 4));// 獲取中間記錄的開始IP地址// strrev函數(shù)在這里的作用是將little-endian的壓縮IP地址轉(zhuǎn)化為big-endian的格式// 以便用于比較,后面相同。
if ($ip $beginip) {// 用戶的IP小于中間記錄的開始IP地址時(shí)
$u = $i - 1;// 將搜索的上邊界修改為中間記錄減一
}else{
fseek($this-fp, $this-getlong3());
$endip = strrev(fread($this-fp, 4)); // 獲取中間記錄的結(jié)束IP地址
if ($ip $endip) {// 用戶的IP大于中間記錄的結(jié)束IP地址時(shí)
$l = $i + 1;// 將搜索的下邊界修改為中間記錄加一
}else{// 用戶的IP在中間記錄的IP范圍內(nèi)時(shí)
$findip = $this-firstip + $i * 7;
break;// 則表示找到結(jié)果,退出循環(huán)
}
}
}//獲取查找到的IP地理位置信息
fseek($this-fp, $findip);
$location['beginip'] = long2ip($this-getlong()); // 用戶IP所在范圍的開始地址
$offset = $this-getlong3();
fseek($this-fp, $offset);
$location['endip'] = long2ip($this-getlong());// 用戶IP所在范圍的結(jié)束地址
$byte = fread($this-fp, 1);// 標(biāo)志字節(jié)
switch (ord($byte)) {
case 1:// 標(biāo)志字節(jié)為1,表示國(guó)家和區(qū)域信息都被同時(shí)重定向
$countryOffset = $this-getlong3();// 重定向地址
fseek($this-fp, $countryOffset);
$byte = fread($this-fp, 1);// 標(biāo)志字節(jié)
switch (ord($byte)) {
case 2:// 標(biāo)志字節(jié)為2,表示國(guó)家信息又被重定向
fseek($this-fp, $this-getlong3());
$location['country'] = $this-getstring();
fseek($this-fp, $countryOffset + 4);
$location['area'] = $this-getarea();
break;
default:// 否則,表示國(guó)家信息沒有被重定向
$location['country'] = $this-getstring($byte);
$location['area'] = $this-getarea();
break;
}
break;
case 2:// 標(biāo)志字節(jié)為2,表示國(guó)家信息被重定向
fseek($this-fp, $this-getlong3());
$location['country'] = $this-getstring();
fseek($this-fp, $offset + 8);
$location['area'] = $this-getarea();
break;
default:// 否則,表示國(guó)家信息沒有被重定向
$location['country'] = $this-getstring($byte);
$location['area'] = $this-getarea();
break;
}
if ($location['country'] == " CZ88.NET") { // CZ88.NET表示沒有有效信息
$location['country'] = "未知";
}
if ($location['area'] == " CZ88.NET") {
$location['area'] = "";
}
$location['country']=iconv('gbk', 'utf-8', $location['country']);
$location['area']=iconv('gbk', 'utf-8', $location['area']);
return $location;
}
}
?
——————————————
這個(gè)類里有個(gè)引入數(shù)據(jù)庫(kù)的行,需要你進(jìn)行更改。
接下來,你在需要使用IP數(shù)據(jù)庫(kù)的頁面中,將這個(gè)類引入,并執(zhí)行下列函數(shù):
$ip = new ip_area();
這個(gè)類不用傳參,自會(huì)得到ip的地理位置。
最后,如果你想得到IP值,那么可以使用以下方法:
————————
function ip(){//-------------------------------------------獲得用戶IP;
if(isset($_SERVER)){
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
$realip=$_SERVER["HTTP_X_FORWARDED_FOR"];
}elseif(isset($_SERVER["HTTP_CLIENT_IP"])){
$realip=$_SERVER["HTTP_CLIENT_IP"];
}else{
$realip=$_SERVER["REMOTE_ADDR"];
}
}else{
if(getenv("HTTP_X_FORWARDED_FOR")){
$realip=getenv("HTTP_X_FORWARDED_FOR");
}elseif(getenv("HTTP_CLIENT_IP")){
$realip=getenv("HTTP_CLIENT_IP");
}else{
$realip=getenv("REMOTE_ADDR");
}
}
return $realip;
}
——————————————————————
//1.連接數(shù)據(jù)庫(kù)
$link?=?@mysql_connect('localhost','root','123456');
//2.判斷是否連接成功
if(!$link)?exit('數(shù)據(jù)庫(kù)連接失敗');
//3.選擇數(shù)據(jù)庫(kù)
mysql_select_db('mydatabase');
//4.設(shè)置字符集??utf8
mysql_set_charset('utf8');
//5.準(zhǔn)備一個(gè)SQL語句
$sql?=?'select?*?from?user';
//6.發(fā)送SQL語句
$result?=?mysql_query($sql);
//7.判斷并處理返回結(jié)果
if($result){
while($row?=?mysql_fetch_array($result)){
$list[]?=?$row;
}
echo?"pre";
print_r($list);
echo?"/pre";
}
//8.釋放資源
mysql_free_result($result);???//查詢操作才需要釋放結(jié)果集
mysql_close();
把不要的數(shù)據(jù)通過sql語句過濾掉,然后分頁輸出。如果你全查出來,裝到數(shù)組,然后判斷,再輸出。太麻煩,效率又不高,不建議這樣做。
查看一下代碼:
?php
//?獲取表單提交值
$student_id?=?intval(trim($_POST['student_id']));
//?頁面表單??可以放單獨(dú)的html文件中,如果放單獨(dú)的html頁面中?form?的action的地址要改成下面的PHP文件名
echo?'form?action=""?method="post"
input?type="text"?name="student_id"?value="{$student_id}"/
input?type="submit"?name="submit"?value="查詢"/
/form';
//?當(dāng)有數(shù)據(jù)提交時(shí)
if?($student_id)
{
$con=?mysql_connect("localhost","root","111")?or?die("連接錯(cuò)誤");
mysql_select_db("examination",$con);
//?查詢
$sql?=?"SELECT?*?FROM?tablename?WHERE?student_id?=?$student_id?";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
//?輸出
echo?'學(xué)號(hào):'.$row['student_id'].'br姓名:'.$row['name'].'br性別:'.$row['gender'].'br分?jǐn)?shù):'.$row['score'];
}
?
在使用php session進(jìn)行數(shù)據(jù)查詢時(shí)主要有3中方法。第一種是使用函數(shù)【mysql_connect()】建立和MYSQL數(shù)據(jù)庫(kù)的連接。mysql_connect()是用來建立和MYSQL數(shù)據(jù)庫(kù)的連接,一共有5個(gè)參數(shù),一般情況下只使用前3個(gè)參數(shù),分別是MySQL服務(wù)器地址、用戶名以及密碼。第二種是使用函數(shù)【mysql_select_db()】指定要操作的數(shù)據(jù)庫(kù)。mysql_select_db()是用來指定要操作的數(shù)據(jù)庫(kù)。要是需要操作的數(shù)據(jù)庫(kù)還沒有創(chuàng)建,則需要?jiǎng)?chuàng)建數(shù)據(jù)庫(kù),然后再創(chuàng)建數(shù)據(jù)庫(kù)中的表。第三種是使用函數(shù)【mysql_query()】查詢指令。mysql_query()是查詢指令的專用函數(shù),所有的SQL語句都通過它執(zhí)行,并返回結(jié)果集。一般情況下這三種方法是最適用的,希望可以解決你的問題。
當(dāng)前題目:php查詢純真數(shù)據(jù)庫(kù),php數(shù)據(jù)庫(kù)查詢語句
鏈接地址:http://chinadenli.net/article3/dssppos.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、Google、域名注冊(cè)、靜態(tài)網(wǎng)站、品牌網(wǎng)站建設(shè)、搜索引擎優(yōu)化
聲明:本網(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í)需注明來源: 創(chuàng)新互聯(lián)