當前位置:首頁 » 編程語言 » php顯示資料庫的資料庫

php顯示資料庫的資料庫

發布時間: 2023-05-12 18:40:58

A. 如何正確理解php獲取顯示資料庫數據函數

1、PHP獲取顯示資料庫數據函數之 mysql_result()

mixed mysql_result(resource result_set, int row [,mixed field])
從result_set 的指定row 中獲取一個field 的數據. 簡單但是效率低.
舉例:

$link1=@mysql_connect("server1",
"webuser","password")

ordie("Couldnotconnect
tomysqlserver!");

@mysql_select_db("company")
ordie("Couldnotselectdatabase!");

$query="selectid,name
fromproctorderbyname";

$result=mysql_query($query);

$id=mysql_result($result,0,"id");

$name=mysql_result($result,0,"name");

mysql_close();

注意,上述代碼只是輸出結果集中的第一條數據的欄位值,如果要輸出所有記錄,需要循環處理.


for($i=0;$i<=mysql_num_rows($result);$i++)

{

$id=mysql_result($result,0,"id");

$name=mysql_result($result,0,"name");

echo"Proct:$name($id)";

}

注意,如果查詢欄位名是別名,則mysql_result中就使用別名.


2、PHP獲取顯示資料庫數據函數之mysql_fetch_row()

array mysql_fetch_row(resource result_set)
從result_set中獲取整行,把數據放入數組中.
舉例(注意和list 的巧妙配合):

$query="selectid,
namefromproctorderbyname";

$result=mysql_query($query);

while(list($id,$name)
=mysql_fetch_row($result)){

echo"Proct:$name($id)";

}


3、PHP獲取顯示資料庫數據函數之mysql_fetch_array()

array mysql_fetch_array(resource result_set [,int result_type])
mysql_fetch_row()的增強版.
將result_set的每一行獲取為一個關聯數組或/和數值索引數組.
默認獲取兩種數組,result_type可以設置:
MYSQL_ASSOC:返回關聯數組,欄位名=>欄位值
MYSQL_NUM:返回數值索引數組.
MYSQL_BOTH:獲取兩種數組.因此每個欄位可以按索引偏移引用,也可以按欄位名引用.

舉例:

$query="selectid,
namefromproctorderbyname";

$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"Proct:$name($id)";

}


4、PHP獲取顯示資料庫數據函數之mysql_fetch_assoc()

array mysql_fetch_assoc(resource result_set)
相當於 mysql_fetch_array($result, MYSQL_ASSOC)


5、PHP獲取顯示資料庫數據函數之mysql_fetch_object()

object mysql_fetch_object(resource result_set)
和mysql_fetch_array()功能一樣,不過返回的不是數組,而是一個對象.
舉例:

$query="selectid,name
fromproctorderbyname";

$result=mysql_query($query);

while($row=mysql_fetch_object
($result)){

$name=$row->name;

$name=$row->id;

echo"Proct:$name($id)";

}

以上這些函數就是PHP獲取顯示資料庫數據函數的全部總結。

B. php中怎麼在表格中顯示資料庫數據

數據上傳到php空間 。。數據代碼填對應的數據內容就可以了。。比如images=「xxxx.jif」把文件gif上傳到空間就好了。。路勁要指示真確。。。

C. 如何使用PHP顯示所有資料庫

如果想全部顯示 就需要循環顯示
你的錯誤在於 $db = mysql_fetch_row($sdb)
你把這個改成 while($db = mysql_fetch_row($sdb)){rows[] =$db;}
$db = mysql_fetch_row($sdb)
因為只會取一個

D. PHP 怎麼顯示資料庫中的數據 求源代碼

讀資料庫,以表格輸出的示例代碼:

<?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"><tr><td>姓名</td><td>年齡</td></tr>';
while($row = $rows->fetch_assoc()){
echo '<tr><td>'.$row['name'].'</td>';
echo '<td>'.$row['address'].'</td></tr>';
}
?

E. php如何查詢資料庫表中的數據並顯示

這個簡單啊!
首頁做個前台輸入姓名和會員卡信息的頁面,我做個簡單的頁面給你看

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""
<htmlxmlns="
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>會員查詢系統</title>
</head>

<body>
<formid="form1"name="form1"method="post"action="test.php">
<p>
<labelfor="name"></label>
<inputtype="text"name="name"id="name"/>
</p>
<p>
<labelfor="vipid"></label>
<inputtype="text"name="vipid"id="vipid"/>
</p>
<p>
<inputtype="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","資料庫用戶名","資料庫密碼");
if(!$con)
{
die('Couldnotconnect:'.mysql_error());
}
$a=mysql_select_db("資料庫名字",$con);
$sql="select*fromkh_customerwherename='$name'andvipid='$vipid'";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo$row['name']."".$row['data'];
echo"<br/>";
}
mysql_close($con);
?>

頁面美化自己去搞!只能幫你這么多了

F. php用表單形式顯示資料庫信息

初學者寫的,你可以試試

<formname="myform"method="post"action="mysql.php">
<tableborder="1">
<tr>
<tdwidth="605"height="51"bgcolor="#CC99FF"colspan="2">
<divalign="center">請輸入用戶名稱
<inputname="txt_user"type="text"id="txt_user"size="25">&nbsp;
<inputtype="submit"name="Submit"value="查詢">
</div>
</td>
</tr>
<tr>
<tdalign='center'>用戶名稱</td>
<tdalign='center'>年齡</td>
</tr>
<?php
//mysql_connect(伺服器,用戶名,密碼)
$link=mysql_connect("localhost","root","root");
//mysql_select_db(資料庫,$link)
$db_selected=mysql_select_db("php_test",$link);
//編碼格式(貌似很重要)
mysql_query("setnames'utf8'");
?>
<?php
$sql=mysql_query("selectname_,age_fromt_user");
$info=mysql_fetch_array($sql);
if($_POST[Submit]=="查詢"){
$txt_user=$_POST[txt_user];
$sql=mysql_query("select*fromt_userwherename_like'%".trim($txt_user)."%'");
$info=mysql_fetch_array($sql);
}
?>
<?php
if($info==false){
echo'<tr><tdwidth="605"height="51"bgcolor="#CC99FF"colspan="2">';
echo"<divalign='center'style='color:#FF0000;font-size:12px;'>對不起,您查找的用戶信息不存在!</div>";
echo'</td></tr>';
}elseif($info){
echo'elseif';
}
?>
<?php
do{
?>
<tralign="center"bgcolor="#FFFFFF">
<tdheight="20"align="center"><?phpecho$info['NAME_']?></td>
<td><?phpecho$info['AGE_']?></td>
</tr>
<?php
}while($info=mysql_fetch_array($sql));

mysql_free_result($sql);
mysql_close($link);
?>
</table>
</form>

G. 如何用php獲取資料庫信息並顯示

獲取ppq資料庫的所有表名的代碼:
?php
$server='localhost';
$user='root';
$pass='12345';
$dbname='ppq';
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die("資料庫系統連接失敗!");
$result=mysql_list_tables($dbname);
if(!$result)
die("資料庫連接失敗!");
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
資料庫中的表
說明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個資料庫名並返回和
mysql_query()
函數很相似的一個結果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個數組,數組的第0列就是數組名,當獲取不到時
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。

H. 如何用PHP實現動態顯示資料庫中內容啊高分求高手解答~!~!!

你所涉及的問題有兩方面。
1、php列表程序;把文章標題、作者、日期、點擊率等列表顯示。
2、php分頁程序;對當所有的列表項進行分面,並按照分頁進行顯示。
因為列表程序可以說是項目中比較重要的程序,就像電腦主板一樣,上面承載有很多的鏈接,相對有點復雜。簡單一點跟你說,又怕你弄不清楚,說詳細一點,你可能又更糊塗了。下面把思路跟你說一下吧:
(1)從資料庫中循環讀出符合要求的記錄,不斷賦值給數組,如$title[$i];
在這期間,要獲取記錄總數、總頁數、當前頁數等內容;
(2)做靜態頁面,循環做表格(行),從數組中不斷取值;
(3)顯示分頁的鏈接和跳轉行;
程序並不是很難,只是比較繁瑣。如果你急需現成的,就把資料庫相關信息發到我郵箱,幫你定製一個,你自己再改。

熱點內容
電腦版我的世界自救練習伺服器 發布:2025-07-18 06:22:25 瀏覽:263
光遇之前為什麼不在安卓上線 發布:2025-07-18 06:20:17 瀏覽:284
c語言偏移 發布:2025-07-18 06:03:01 瀏覽:889
甘肅雲堤伺服器 發布:2025-07-18 06:02:52 瀏覽:650
狼人殺腳本群 發布:2025-07-18 06:00:45 瀏覽:289
oracle10g安裝linux 發布:2025-07-18 05:53:33 瀏覽:619
百科php 發布:2025-07-18 05:53:33 瀏覽:879
刪除觸發器的sql語句 發布:2025-07-18 05:44:42 瀏覽:678
安卓手機adv是什麼意思 發布:2025-07-18 05:44:02 瀏覽:842
ims醫葯資料庫 發布:2025-07-18 05:33:52 瀏覽:815