將數(shù)據(jù)print_r 打印出來 如:
創(chuàng)新互聯(lián)專注于福貢網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供福貢營銷型網(wǎng)站建設(shè),福貢網(wǎng)站制作、福貢網(wǎng)頁設(shè)計(jì)、福貢網(wǎng)站官網(wǎng)定制、成都小程序開發(fā)服務(wù),打造福貢網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供福貢網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
include_once("connect.php");
$q=mysql_query("select * from comments");
while($row=mysql_fetch_array($q)){
$comments[] = array("id"=$row[id],"user"=$row[user],"comment"=$row[comment],"addtime"=$row[addtime]);
}
print_r($comments);
echo json_encode($comments);
結(jié)果已經(jīng)有了,我就說下這句話的區(qū)別
mysql_select_db,字面上就能理解,選擇數(shù)據(jù)庫
去PHP手冊(cè)中可以發(fā)現(xiàn)該函數(shù)的返回值是bool,也就是布爾值
bool mysql_select_db ( string $database_name [, resource $ link_identifier ] )
只是確定操作是否成功
$result = mysql_query($sql, $link); // 執(zhí)行查詢語句
是執(zhí)行查詢語句,這時(shí)返回的是
resource mysql_query ( string $query [, resource $link_identifier ] )
資源符號(hào),通過var_dump($result)可以看到該變量的類型,不是數(shù)組
隨后通過mysql_fetch_array($result);獲取實(shí)際查詢語句所能獲取的數(shù)據(jù)
每次操作,返回一行數(shù)據(jù)
該操作會(huì)變相的移動(dòng)該資源的指針,PHP的概念里面沒有指針,但需要知道該函數(shù)可以多次執(zhí)行
概念和foreach一致
所以通過
while ($bookInfo = mysql_fetch_array($result)){
}
可以獲取所有的行數(shù)據(jù)
如果沒有數(shù)據(jù)會(huì)返回false,所以while會(huì)自動(dòng)停止循環(huán)
先需要?jiǎng)?chuàng)建數(shù)據(jù)庫連接。
這里假設(shè)連接對(duì)象為$dbo
$row = $dbo-execute($sql);
if(mysql_num_rows($row) 0)
{
while($rs = mysql_fetch_array($row))
{
echo $rs['classname'];
}
};
這是普通的,
看了你的SQL。貌似用的是帝國CMS?
$sql1111="select classid from phome_enewslinkclass where classname='東方大廈'";
$csql=$empire-query($sql1111);
while($rs=$empire-fetch($csql))
{
echo $rs[classname];
}
您好,PHP輸出數(shù)據(jù)有四種方式,echo、var_dump、print_r、retrun(這個(gè)一般是PHP框架常用)
這個(gè)簡單啊!
首頁做個(gè)前臺(tái)輸入姓名和會(huì)員卡信息的頁面,我做個(gè)簡單的頁面給你看
!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ù)庫用戶名","數(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);
?
頁面美化自己去搞!只能幫你這么多了
用聯(lián)合查詢就可以實(shí)現(xiàn)
一般包括左外連接,右外連接和內(nèi)連接
可以用on設(shè)置每兩個(gè)表之間的關(guān)聯(lián)關(guān)系,查詢后遍歷輸出到頁面就可以了