了清楚地說(shuō)明使用AJAX從數(shù)據(jù)庫(kù)訪問(wèn)信息的難易程度,我們將動(dòng)態(tài)構(gòu)建MySQL查詢并將結(jié)果顯示在“ ajax.html”上。但是在繼續(xù)之前,讓我們做基礎(chǔ)工作。使用以下命令創(chuàng)建表。
注 –我們假設(shè)您具有足夠的特權(quán)來(lái)執(zhí)行以下MySQL操作。
CREATE TABLE 'ajax_example' (
'name' varchar(50) NOT NULL,
'age' int(11) NOT NULL,
'sex' varchar(1) NOT NULL,
'wpm' int(11) NOT NULL,
PRIMARY KEY ('name')
)
現(xiàn)在,使用以下SQL語(yǔ)句將以下數(shù)據(jù)轉(zhuǎn)儲(chǔ)到該表中:
INSERT INTO 'ajax_example' VALUES ('Jerry', 120, 'm', 20);
INSERT INTO 'ajax_example' VALUES ('Regis', 75, 'm', 44);
INSERT INTO 'ajax_example' VALUES ('Frank', 45, 'm', 87);
INSERT INTO 'ajax_example' VALUES ('Jill', 22, 'f', 72);
INSERT INTO 'ajax_example' VALUES ('Tracy', 27, 'f', 0);
INSERT INTO 'ajax_example' VALUES ('Julie', 35, 'f', 90);
現(xiàn)在讓我們擁有客戶端HTML文件ajax.html,它將具有以下代碼-
<html>
<body>
<script language = "javascript" type = "text/javascript">
<!--
//Browser Support Code
function ajaxFunction() {
var ajaxRequest; // The variable that makes Ajax possible!
try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4) {
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// Now get the value from user and pass it to
// server script.
var age = document.getElementById('age').value;
var wpm = document.getElementById('wpm').value;
var sex = document.getElementById('sex').value;
var queryString = "?age = " + age ;
queryString += "&wpm = " + wpm + "&sex = " + sex;
ajaxRequest.open("GET", "ajax-example.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
<form name = 'myForm'>
Max Age: <input type = 'text' id = 'age' /> <br />
Max WPM: <input type = 'text' id = 'wpm' /> <br />
Sex:
<select id = 'sex'>
<option value = "m">m</option>
<option value = "f">f</option>
</select>
<input type = 'button' onclick = 'ajaxFunction()' value = 'Query MySQL'/>
</form>
<div id = 'ajaxDiv'>Your result will display here</div>
</body>
</html>
注 –在查詢中傳遞變量的方式符合HTTP標(biāo)準(zhǔn),并具有formA。
URL?variable1 = value1;&variable2 = value2;
上面的代碼將為您提供如下屏幕-
最高年齡:
最高WPM:
性別: 米 F
輸入后,結(jié)果將顯示在此部分中。
注意 -這是一個(gè)虛擬屏幕。
您的客戶端腳本已準(zhǔn)備就緒。現(xiàn)在,我們必須編寫(xiě)服務(wù)器端腳本,該腳本將從數(shù)據(jù)庫(kù)中獲取年齡,wpm和性別,并將其發(fā)送回客戶端。將以下代碼放入文件“ ajax-example.php”中。
<?php
$dbhost = "localhost";
$dbuser = "dbusername";
$dbpass = "dbpassword";
$dbname = "dbname";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
$age = $_GET['age'];
$sex = $_GET['sex'];
$wpm = $_GET['wpm'];
// Escape User Input to help prevent SQL Injection
$age = mysql_real_escape_string($age);
$sex = mysql_real_escape_string($sex);
$wpm = mysql_real_escape_string($wpm);
//build query
$query = "SELECT * FROM ajax_example WHERE sex = '$sex'";
if(is_numeric($age))
$query .= " AND age <= $age";
if(is_numeric($wpm))
$query .= " AND wpm <= $wpm";
//Execute query
$qry_result = mysql_query($query) or die(mysql_error());
//Build Result String
$display_string = "<table>";
$display_string .= "<tr>";
$display_string .= "<th>Name</th>";
$display_string .= "<th>Age</th>";
$display_string .= "<th>Sex</th>";
$display_string .= "<th>WPM</th>";
$display_string .= "</tr>";
// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($qry_result)) {
$display_string .= "<tr>";
$display_string .= "<td>$row[name]</td>";
$display_string .= "<td>$row[age]</td>";
$display_string .= "<td>$row[sex]</td>";
$display_string .= "<td>$row[wpm]</td>";
$display_string .= "</tr>";
}
echo "Query: " . $query . "<br />";
$display_string .= "</table>";
echo $display_string;
?>
現(xiàn)在嘗試在“ 最大年齡”或任何其他框中輸入有效值(例如120),然后單擊“查詢MySQL”按鈕。
最高年齡:
最高WPM:
性別: 米 F
輸入后,結(jié)果將顯示在此部分中。
如果您已成功完成本課程,那么您將知道如何結(jié)合使用MySQL,PHP,HTML和Javascript編寫(xiě)AJAX應(yīng)用程序。
上好,我是老楊。
不止一個(gè)粉絲好奇地問(wèn)我,思科認(rèn)證和華為認(rèn)證的真題水平到底有多難。
上一期,我已經(jīng)更新了華為的真題,感興趣的朋友可以文章鏈接查看:《華為原廠真題》
思科認(rèn)證技術(shù)點(diǎn)到底有多少,這么一看,多一目了然。
光看是不是沒(méi)感覺(jué)啊?
老楊還備了12道難度適中的思科認(rèn)證真題,不多不少,做一遍不就知道難度了嗎?
為了還原體驗(yàn)感,本次試題的內(nèi)容均為英文,這樣就可以更好地感受一下自己的水平。
為了更好解答粉絲疑惑,本次的測(cè)試題老楊專(zhuān)門(mén)放上了解析,供君理解和參考。
今日文章閱讀福利:《思科CCNA題庫(kù)(精選328頁(yè))》
作為練手或者是體驗(yàn)考試氛圍,這份CCNA的考試真題很適合你。官方發(fā)布,題庫(kù)每道題都有中文翻譯。私信老楊,備注“CCNA”,前6名粉絲可以免費(fèi)領(lǐng)取閱讀福利!
1. Which two statements are true about the command ip route 172.16.3.0 255.255.255.0 192.168.2.4? (Choose two.)
A. It establishes a static route to the 172.16.3.0 network.
B. It establishes a static route to the 192.168.2.0 network.
C. It configures the router to send any traffic for an unknown destination to the 172.16.3.0 network.
D. It configures the router to send any traffic for an unknown destination out the interface with the address 192.168.2.4.
E. It uses the default administrative distance.
F. It is a route that would be used last if other routes to the same destination exist.
2. A company is installing IP phones. The phones and office computers connect to the same device. To ensure maximum throughput for the phone data, the company needs to make sure that the phone traffic is on a different network from that of the office computer data traffic. What is the best network device to which to directly connect the phones and computers, and what technology should be implemented on this device? (Choose two.)
A. hub
B. router
C. switch
D. STP
E. subinterfaces
F. VLAN
3. Refer to the exhibit. A network associate needs to configure the switches and router in the graphic so that the hosts in VLAN3 and VLAN4 can communicate with the enterprise server in VLAN2. Which two Ethernet segments would need to be configured as trunk links? (Choose two.)
A. A
B. B
C. C
D. D
E. E
F. F
4. Which two values are used by Spanning Tree Protocol to elect a root bridge? (Choose two.)
A. amount of RAM
B. bridge priority
C. IOS version
D. IP address
E. MAC address
F. speed of the links
5. A network administrator changes the configuration register to 0x2142 and reboots the router. What are two results of making this change? (Choose two.)
A. The IOS image will be ignored.
B. The router will prompt to enter initial configuration mode.
C. The router will boot to ROM.
D. Any configuration entries in NVRAM will be ignored.
E. The configuration in flash memory will be booted.
1-5:AE,CF,CF,BE,BD
第1題解析:這條路由的意思是如果想去 172.16.3.0 網(wǎng)絡(luò),就把 192.168.2.4 作為下一跳,同時(shí)管理距離沒(méi)有改,靜態(tài)路由默認(rèn)的管理距離就是默認(rèn) 1
第2題解析:題目大意是語(yǔ)音電話和公司電腦在一個(gè)網(wǎng)絡(luò),如果想最大程度保證電話的數(shù)據(jù)流不被其他數(shù)據(jù)流影響,應(yīng)該如何選擇設(shè)備,在這里交換機(jī)每個(gè)端口都是一個(gè)沖突域,可使通訊效率更好,還可以把電話端口和數(shù)據(jù)流端口劃分到不同 vlan 中,做到互不影響,故選 CF。
第3題解析:這個(gè)題目考查的是對(duì)單臂路由的了解, 很明顯的是路由器與 交換機(jī),以及交換機(jī)與交換機(jī)之間需要封裝Trunk 鏈路。故正確答案為 C和F
第4題解析:選舉根橋順序記住兩個(gè)參數(shù)就可以了,一個(gè)是橋優(yōu)先級(jí), 一個(gè)是橋 MAC 地址。
第5題解析:分析我們路由器默認(rèn)的 IOS 寄存值為 0X2102 ,下次啟動(dòng)會(huì)加載上次的所做的配置;0X2142 會(huì)忽略上次的配置。
A:IOS的映像將被忽略。錯(cuò)
B:路由器將迅速進(jìn)入初始配置模式, 這個(gè)是正確的。
C:路由器將從只讀 存儲(chǔ)器(R OM )上啟動(dòng)。錯(cuò)
D:NVRAM 中的任何配置將被完全忽略。正確
E:將從閃存的配置中啟動(dòng)。錯(cuò)
6. Switch ports operating in which two roles will forward traffic according to the IEEE 802.1w standard? (Choose two.)
A. alternate
B. backup
C. designated
D. disabled
E. root
7. What are two advantages of Layer 2 Ethernet switches over hubs? (Choose two.)
A. decreasing the number of collision domains
B. filtering frames based on MAC addresses
C. allowing simultaneous frame transmissions
D. increasing the size of broadcast domains
E. increasing the maximum length of UTP cabling between devices
8. Refer to the exhibit. The networks connected to router R2 have been summarized as a 192.168.176.0/21 route and sent to R1. Which two packet destination addresses will R1 forward to R2? (Choose two.)
A. 192.168.194.160
B. 192.168.183.41
C. 192.168.159.2
D. 192.168.183.255
E. 192.168.179.4
F. 192.168.184.45
9.Which command must you use to verify hostname-to-IP-address mapping information?
A. show mac-address-table
B. show sessions
C. show arp
D. show hosts
10. Refer to the exhibit. Which three statements are true about how router JAX will choose a path to the 10.1.3.0/24 network when different routing protocols are configured? (Choose three.)
A:By default, if RIPv2 is the routing protocol, only the path JAX-ORL will be installed into the routing table.
B:The equal cost paths JAX-CHI-ORL and JAX- NY-ORL will be installed in the routing table if RIPv2 is the routing protocol.
C:When EIGRP is the routing protocol, only the path JAX-ORL will be installed in the routing table by default.
D:When EIGRP is the routing protocol, the equal cost paths JAX-CHI-ORL, and JAX-NY-ORL will be installed in the routing table by default.
E:With EIGRP and OSPF both running on the network with their default configurations, the EIGRP paths will be installed in the routing table.
F:The OSPF paths will be installed in the routing table, if EIGRP and OSPF are both running on the network with their default configurations.
6-10:CE,BC,BE,D,ADE
第6題解析:題目考查的是 802.1w 也就是 RSTP。RSTP 定義了3 種狀態(tài):放棄、學(xué)習(xí)和轉(zhuǎn)發(fā)。根或指定端口在拓?fù)浣Y(jié)構(gòu)中發(fā)揮著積極作用,而替代或備份端口不參與主動(dòng)拓?fù)浣Y(jié)構(gòu)。在穩(wěn)定的網(wǎng)絡(luò)中,根和指定端口處于轉(zhuǎn)發(fā)狀態(tài),替代和備份端口則處于放棄狀態(tài)。
第7題解析:太簡(jiǎn)單了,不多贅述。
第8題解析:首先來(lái)看一下這個(gè)匯總地址 192.168.176.0/21 128 64 32 16 8 4 2 1 1 0 1 1 0 0 0 0= 176 掩碼是21位。
從這個(gè)這個(gè)匯總地址,我們能得出被匯總地址的范圍是192.168.176.1 – 192.168.183.254,192.168.183.255 是廣播地址,通過(guò)以上分析我們可以馬上選出答案 BE是正確的
第9題解析:A選項(xiàng)命令可以查看到mac地址表,B選項(xiàng)命令可以查看到會(huì)話和連接用戶信息,C選項(xiàng)命令可以查看到arp解析條目,D選項(xiàng)命令可以看到主機(jī)名和IP地址的映射關(guān)系。
第10題解析:
此題考查的是 RIP、EIGRP、OSPF 的選路問(wèn)題。默認(rèn)情況下EIGRP 要優(yōu)于OSPF 優(yōu)于 RIP EIGRP 時(shí)支持負(fù)載均衡。等價(jià)于非等價(jià)都支持。
11. Which three statements are typical characteristics of VLAN arrangements? (Choose three.)
A. A new switch has no VLANs configured.
B. Connectivity between VLANs requires a Layer 3 device.
C. VLANs typically decrease the number of collision domains.
D. Each VLAN uses a separate address space.
E. A switch maintains a separate bridging table for each VLAN.
F. VLANs cannot span multiple switches.
12. Refer to the exhibit. A network administrator is adding two new hosts to SwitchA. Which three values could be used for the configuration of these hosts? (Choose three.)
A. host A IP address: 192.168.1.79
B. host A IP address: 192.168.1.64
C. host A default gateway: 192.168.1.78
D. host B IP address: 192.168.1.128
E. host B default gateway: 192.168.1.129
F. host B IP address: 192.168.1.190
11-12:BDE,ACF
第11題解析:
A:新交換機(jī)都有一個(gè)默認(rèn) vlan1,因此錯(cuò)
B:VLANs 之間的聯(lián)通的需求是一個(gè)三層設(shè)備,正確。
C:VLANs 代表性的能降低沖突域的數(shù)量,錯(cuò)。
沖突域和 vlan沒(méi)關(guān)系 ,vlan分割的是廣播域,一個(gè)交換機(jī)端口就是一個(gè)沖突域。
D:每個(gè) VLAN 使用分離的地址空間,正確
E:一個(gè)交換機(jī)在每個(gè) VLAN 中保持存放一個(gè)分離的橋接
表,命令 show mac-address-table vlan 可以看見(jiàn)
F:VLANs 不能跨越多個(gè)交換機(jī),錯(cuò)
第12題解析:此題考點(diǎn)又是單臂路由,以及 VLSM.不同的 vlan在不同網(wǎng)段, 路由器上的子接口 ip地址也應(yīng)該和每個(gè) vlan 在一個(gè)網(wǎng)段,并且其 ip地址應(yīng)該是每個(gè)vlan的網(wǎng)關(guān)路由器的配置已經(jīng)固定,那么主機(jī)的上的ip地址和網(wǎng)關(guān)配置就應(yīng)該和路由器的配置保持一致。
host A 在交換機(jī) 6號(hào)口上,對(duì)應(yīng) Vlan10 查看右邊的圖可以看出其網(wǎng)關(guān)為192.168.1.78 因此答案C是正確的。
host B 在交換機(jī) 9號(hào)口上,對(duì)應(yīng) vlan20 ,查看右邊的圖可以看出其網(wǎng)關(guān)為192.168.1.130再來(lái)分析 host A host B 的IP 地址,肯定必須和他的網(wǎng)關(guān)在同一個(gè)網(wǎng)段上,這樣我們很快就選出了答案。
整理:老楊丨9年資深網(wǎng)絡(luò)工程師,更多網(wǎng)工提升干貨,請(qǐng)關(guān)注公眾號(hào):網(wǎng)絡(luò)工程師俱樂(lè)部
工作中有時(shí)候需要給表格加目錄,以便更快捷更直觀的進(jìn)入你想要的工作表,今天分享的代碼很短,我盡量把它解釋的更簡(jiǎn)單。
綠色字體是注釋
代碼演示
For Each是變量在某個(gè)集合里面循環(huán),這個(gè)集合可以是單元格,可以是工作表,也可以是工作薄,客官可以自行修改代碼進(jìn)行嘗試。
代碼如下:
Dim a As Byte, d As Byte
Dim arr As Range, str As String
Sub xjclj()
a = ActiveWorkbook.Sheets.Count
d = 2
For Each arr In Selection.Resize(a - 1, 1)
str = ActiveWorkbook.Sheets(d).Name
ActiveSheet.Hyperlinks.Add Anchor:=arr, Address:="", SubAddress:= _
str & "!A1", TextToDisplay:=str
d = d + 1
Next
End Sub
如果對(duì)我的講解有疑問(wèn)歡迎留言,如果覺(jué)得有用,請(qǐng)別忘了收藏點(diǎn)贊,歡迎轉(zhuǎn)發(fā),謝謝
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。