新聞中心
php如何查詢數(shù)據(jù)庫表中的數(shù)據(jù)并顯示
這個簡單啊!
創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于網(wǎng)站制作、做網(wǎng)站、中站網(wǎng)絡推廣、小程序開發(fā)、中站網(wǎng)絡營銷、中站企業(yè)策劃、中站品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)公司為所有大學生創(chuàng)業(yè)者提供中站建站搭建服務,24小時服務熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
首頁做個前臺輸入姓名和會員卡信息的頁面,我做個簡單的頁面給你看
!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會員查詢系統(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
然后我給你一個test.php的文件代碼:
?php
$name????=????trim($_POST['name']);
$vipid????=????trim($_POST['vipid']);
$con?=?mysql_connect("127.0.0.1","數(shù)據(jù)庫用戶名","數(shù)據(jù)庫密碼");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
$a????=????mysql_select_db("數(shù)據(jù)庫名字",?$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ù)庫表中的一條記錄
我直接在這給你修改答案算了
使用的時候刪除行號 修改數(shù)據(jù)庫配置 如果想使用 頁面不刷新查詢數(shù)據(jù)庫 需要使用JQUERY 如果有需要給我留言
1 ?php
2 if(isset($_POST['submit'])$_POST['submit']=='提交'){
3 //判斷是否是提交過來的
4 $intext = $_POST['intext'];
5 if($intext!=null||$intext!=''){
6 $link = mysql_connect("localhost", "root", "123456");
7 //數(shù)據(jù)庫配置信息 第一個參數(shù)數(shù)據(jù)庫位置第二個是用戶名第三個是密碼
8 mysql_select_db("szn_test");
9 //設(shè)置要使用的數(shù)據(jù)庫
10 $sql = "select * from demo where res = '".$intext."'";
11 //SQL語句
12 var_dump($sql);
13 $res = mysql_query($sql);
14 $arr = array();
15 //吧結(jié)果存入數(shù)組 并記錄數(shù)組長度
16 $count = 0;
17 while($data = mysql_fetch_array($res)){
18 $arr[$count] = $data;
19 $count++;
20 }
21 //關(guān)閉數(shù)據(jù)庫
22 mysql_close($link);
23 }
24 }
25
26 ?
27 html
28 head
29 title/title
30 /head
31 body
32 form id="form1" method="post" action="demo.php"
33 input type="text" name="intext"
34 input type="submit" name="submit" value="提交"
35 /form
36 ?php
37 if(isset($arr)$arr != null){
38 for($i = 0; $i $count; $i++){
39 foreach($arr[$i] as $key = $value){
40 echo "key:".$key." value:".$value;
41 echo " ";
42 }
43 echo "br";
44 }
45 }
46 ?
47 /body
48 /html
這個是數(shù)據(jù)庫查詢代碼 你可以看以下對照著修改修改
php 查詢數(shù)據(jù)庫表 判斷 某值是否存在
代碼如下:
?php
$sql="select * from checklist where game_id=$gid and task='$task' and status='$status'";
$result=mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if (!mysql_num_rows($result))
? {
? ? ? echo "record doesn't exist~~~~~!!!!!!";
? }
else
? {? ? ? ? ? ? ?// echo mysql_num_rows($result)."\n";
? ? ? echo $row['game_id'];
? ? ? echo $row['task'];
? }
?
擴展資料
訪問MySql一般步驟
1)連接MySql服務器
使用mysql_connect()函數(shù)建立與MySql服務器的連接。
2)選擇MySql數(shù)據(jù)庫
使用mysql_select_db()函數(shù)選擇MySql服務器上的數(shù)據(jù)庫,并與數(shù)據(jù)庫建立連接。
3)執(zhí)行SQL語句
使用mysql_query()函數(shù)執(zhí)行SQL語句。(包括增加、刪除、修改、查詢、顯示)
4)關(guān)閉結(jié)果集
使用mysql_free_result($result)關(guān)閉結(jié)果集,以釋放資源。
網(wǎng)站標題:php5.7查詢數(shù)據(jù)表 php數(shù)據(jù)庫查詢結(jié)果處理
URL分享:http://fisionsoft.com.cn/article/dddejoe.html