兩種情況。

創(chuàng)新互聯(lián)是專業(yè)的青原網(wǎng)站建設(shè)公司,青原接單;提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行青原網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
1、你剛學(xué)php沒有使用框架。每一個框架的的獲取數(shù)據(jù)的方法不一樣。他們功能的特點(diǎn)是都會配置數(shù)據(jù)連接,所以你只要按照他們的配置,進(jìn)行配置就可以,一般要用戶名密碼,數(shù)據(jù)庫名。例如speed的位:
$spConfig = array(
'db' = array(
'host' = 'xxxx',
'login' = 'xxx',
'password' = 'xx',
'database' = 'xxx')
)
然后在模型(sql語句,指出表名,字段)中寫好表,以獲取。具體的學(xué)框架。寫出來太多了。
2、直接連接使用。我寫了點(diǎn)代碼如下:
$host ='';/主機(jī)
$login = '';//用戶
$password = '';//密碼
$database = '';//數(shù)據(jù)庫
$con = mysql_connect($host,$login,$password);
if(!$con)
{
die('could no neect'.mysql_error());
}
mysql_select_db($database,$con);
$result = mysql_query("select test from Test)//你的表
while($row = mysql_fetch_array($result))
{
echo $row[test];//字段名
}
mysql_close($con);
不懂再問!
親,你的想法有問題,這是不符合要求的。
數(shù)據(jù)庫中有很多的表,表中有字段。因此你不可能查詢數(shù)據(jù)庫中的id和news,而是只能在特定的表上查詢。同時sql語法也要求
select
fields
from
table_name而不是db_name哦。
舉例來說,保存新聞的表名字是news,
位于數(shù)據(jù)庫
my_test_db中,那么應(yīng)該
$con = mysql_connect("127.0.0.1", "123", "123");
mysql_select_db('my_test_db', $con);
$sql = "select id, news from news";后面的代碼就一樣了
獲取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()
接受一個數(shù)據(jù)庫名并返回和
mysql_query()
函數(shù)很相似的一個結(jié)果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個數(shù)組,數(shù)組的第0列就是數(shù)組名,當(dāng)獲取不到時
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
讀數(shù)據(jù)庫,以表格輸出的示例代碼:
?php
header('Content-type:text/html;charset=utf-8');
$db = new mysqli('localhost','root','root','books');
$rows = $db-query('SELECT * FROM customers');
echo 'table border="1"trtd姓名/tdtd年齡/td/tr';
while($row = $rows-fetch_assoc()){
echo 'trtd'.$row['name'].'/td';
echo 'td'.$row['address'].'/td/tr';
}
?
這個簡單啊!
首頁做個前臺輸入姓名和會員卡信息的頁面,我做個簡單的頁面給你看
!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ù)庫字段內(nèi)容 php數(shù)據(jù)庫文件
新聞來源:http://chinadenli.net/article22/hpjijc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、服務(wù)器托管、標(biāo)簽優(yōu)化、網(wǎng)站設(shè)計(jì)公司、App設(shè)計(jì)、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)