不得不補 PHP的JSON, SQL

2022-01-30 06:29:18 字數 4944 閱讀 2765

學習自:

前端頁面:

doctype html

>

<

html

>

<

head

>

<

title

>第二個練習

title

>

<

meta

charset

="utf-8"

>

<

meta

name

="viewport"

content

="width=device-width"

>

<

script

src="jquery-1.8.3.min.js"

>

script

>

<

script

>$("

document

").ready(

function

();

// getjson() 方法使用 ajax 的 http get 請求獲取 json 資料。

$.getjson(url,data,

function

(res));

vardata=;

$.getjson(url,data,

function

(res));

vardata

=;

$.getjson(url,data,

function

(res));

});script

>

head

>

<

body

>

<

h2>一維陣列練習

h2>

<

input

type

="text"

name

="username"

id="username"

/><

br />

<

input

type

="text"

name

="password"

id="password"

/><

br />

<

h2>多維陣列練習(一組會員資訊)

h2>

<

textarea

id="members"

style

="width:200px;height:60px"

>

textarea

>

<

h2>物件實戰(一組位址資訊)

h2>

<

textarea

id="address"

style

="width:300px;height:60px"

>

textarea

>

body

>

html

>

後端頁面, 也就是前端所請求的 ser2.php :

<?php

//示例資料

$member['username'] = 'alex';

$member['password'] = '123456';

$do = $_request['do'];

$members['1']['username'] = 'thanos';

$members['1']['password'] = 'wuxianshoutao';

$members['2']['username'] = '雷神';

$members['2']['password'] = 'thor';

$members['2']['address'] = 'arsjade';

$members['three']['members']['username'] = '這是該死的第三個';

class

addressclass

public

function

getaddress()

}$addressobj = new

addressclass();

$addressobj->setaddress($members

);switch($do

)

不得不補的小知識,也得花點時間。

-------------------------------------分割線-------------------------------------

將json轉為js物件

doctype html

>

<

html

>

<

head

>

<

meta

charset

="utf-8"

>

<

title

>菜鳥教程(runoob.com)

title

>

head

>

<

body

>

<

h2>為 json 字串建立物件

h2>

<

p id

="demo"

>

p>

<

script

>

vartext ='

,'+'

,'+'

]}';

obj

=json.parse(text);

document.getelementbyid(

"demo

").innerhtml

=obj.sites[

0].name +"

"+obj.sites[

0].url;

varx;

for(x

inobj.sites)

script

>

body

>

html

>

將** 轉為json

doctype html

>

<

html

>

<

head

>

<

meta

charset

="utf-8"

>

<

title

>菜鳥教程(runoob.com)

title

>

head

>

<

body

>

<

p id

="demo"

>

p>

<

script

>

varstr

=str_pretty1

=json.stringify(str)

document.write(

"只有乙個引數情況:");

document.write( ""

);document.write(""

+str_pretty1 +"

"

);document.write( ""

);str_pretty2

=json.stringify(str,

null, 4

) //

使用四個空格縮排

document.write(

"使用引數情況:");

document.write( ""

);document.write(

"

"+

str_pretty2 +"

"

); //

pre 用於格式化輸出

script

>

body

>

html

>

sql 語句的幾個小知識點:

1. 取某列varchar中第3位僅為數字的,用like肯定比substring要快:

select a.wono from

[dbo

].[temp

]as a where a.wono like

'__[0-9]%'--

like 中的 下劃線表示單個字元,所以用了2個佔2位, [0-9]表示這個位置僅為數字, % 不用解釋了吧。

看著有點正規表示式的樣子,那麼 like '__[^0-9]%'  就表示不是數字的。

2. 兩列nchar 拼接時用+號連線,去空格時只能用 ltrim 和 rtrim 

3. 數字型的日期'20180501' 想要計算距今天數,需要先用cast轉換為日期。

select

datediff(day, cast(rtrim(opndt8) as

datetime),getdate()) as days --

得到距今天數

反過來,日期轉為8位數字: convert(varchar(8),getdate(),112)  

4. 使用exists代替直接in:

select

*from

emp

where deptno in(select deptno from dept );

select

*from

emp e

where

exists(select

1from dept d where d.deptno=e.deptno );

不得不說的「跳槽」

現實中不難發現 越是高階人才,適合的機會就越少 的現象。身處金字塔中上層的人員,無論是職位還是薪水,起點都很高,這客觀上造成適合的職位機會少,職業路徑轉換成本過高等問題。我個人認為,it技術高層人士,如果要跳槽,務必要注意三宜和三忌。忌 病急亂投醫 宜 方法得當 公升遷至較高職位的人,大多都多年不找...

不得不寫點VB程式

此種方式是以行為單位進行讀取的基本單位,主要應用的方法和函式有open,close,line input,freefile,eof等。下面先簡述其功能然後結合 示例進行說明。open 顧名思義,它的作用是開啟檔案,換而言之開啟某個檔案就是獲得某個的控制權,一般情況下當檔案處於開啟狀態時只有開啟者才能...

關於基礎,不得不說

最近遇到好多問題,都與基本概念相關。忍不住,就想多說幾句。研究生面試,我出了乙個問題,乙個100khz的方波訊號,幅度大約是幾伏的數量級,想測量其有效值,用什麼儀器,怎麼測?多數學生一臉茫然,搞的我不好意思,慚愧題目是不是太難了。我急了,問學生,乙個1.5v的電池,其電壓有效值是多少?學生問我,直流...