<form action="" method="post" name="form1"><br>
Input address book data:<br>
name:<input name="name" type="text" value=""><br>
phone:<input name="phone" type="text" value=""><br>
address:<input name="address" type="text" value=""><br>
<input name="submit" type="submit" value="add"><br>
<?php
mysql_connect('localhost','root','student') or die("connect error!");
mysql_select_db('phone') or die("db error");
mysql_query("SET NAMES 'utf8'");
mysql_query("CREATE TABLE `address_book` (
`sid` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 20 ) NOT NULL ,
`phone` VARCHAR( 20 ) NOT NULL ,
`address` VARCHAR( 20 ) NOT NULL
) ENGINE = MYISAM ;");
if(count($_POST)>0) {
// 準備更新資料的語法
$name = $_POST["name"];
$phone = $_POST["phone"];
$address = $_POST["address"];
mysql_query("INSERT INTO address_book (name, phone, address )
VALUES( '$name', '$phone', '$address')");
}
$result = mysql_query("SELECT * FROM address_book");
makeTable($result);
function makeTable($result)
{
echo "<table border='1'>";
//設定Title
echo "<tr><td>sid</td>";
echo "<td>name</td>";
echo "<td>phone</td>";
echo "<td>address</td>";
echo "<td></td>";
echo "<td></td></tr>";
//讀取內容
while($row = mysql_fetch_assoc($result)) {
echo "<tr><td>$row[sid]</td>";
echo "<td>$row[name]</td>";
echo "<td>$row[phone]</td>";
echo "<td>$row[address]</td>";
echo "<td><a href=add_mysql.php?op=del&sid=$row[sid]>del</a></td>";
echo "<td><a href=update.php?sid=$row[sid]&name=$row[name]&phone=$row[phone]&address=$row[address]>update</a></td></tr>";
}
echo "</table>";
}
?>
「Chifu」的全部文章
Sorted 範例
dic = {'Tom': 90, 'Mary':56, 'Bob':77, 'Alan': 80, 'Sunny':100}
lis = [90,56,77,80,100]
students = [('Tom', 90), ('Mary', 56), ('Bob', 77), ('Alan', 80), ('Sunny', 100)]
def temp_function(list):
print(list)
return list[0]
'''
print(dic)
print(dic.items())
print(dic.keys())
print(dic.values())
'''
print('dic sorted:')
print(sorted(dic.items(), key = temp_function))
print('lis sorted:')
print(sorted(lis))
print('students sorted:')
print(sorted(students, key= temp_function))
#lambda
print('lambda')
print(sorted(dic.items(), key = lambda x : x[1]))
受保護的文章:python_09_hw
受保護的文章:python_07_hw
受保護的文章:python_06_hw
受保護的文章:python_05_hw
url編碼範例
# -*- coding: utf-8 -*-
import urllib.request
urlstr=urllib.parse.quote('鋼鐵人')
url = 'http://tw.movie.yahoo.com/moviesearch_result.html?qmv='+urlstr
response = urllib.request.urlopen(url)
html = response.read().decode('utf_8')
print(html)
參考電子書
PyQT 按鈕事件範例
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created: Sat Jun 8 21:02:00 2013
# by: PyQt4 UI code generator 4.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(329, 414)
self.lineEdit = QtGui.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(30, 30, 251, 31))
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(30, 100, 251, 31))
self.label.setObjectName(_fromUtf8("label"))
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(120, 250, 75, 41))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.label_2 = QtGui.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(30, 160, 251, 31))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.lineEdit, QtCore.SIGNAL(_fromUtf8("textChanged(QString)")), self.label.setText)
QtCore.QMetaObject.connectSlotsByName(Dialog)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL("clicked()"), self.btnTest)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.label.setText(_translate("Dialog", "TextLabel", None))
self.pushButton.setText(_translate("Dialog", "PushButton", None))
self.label_2.setText(_translate("Dialog", "TextLabel", None))
def btnTest(self):
self.label_2.setText(self.lineEdit.text())
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
sqlite 連線範例
# -*- coding: utf-8 -*-
import sqlite3
conn = sqlite3.connect('starbucks.sqlite')
cur=conn.cursor()
cur.execute("insert into 'stores' ('longitude','latitude','name','address','tel','wifi','notes') VALUES(20,100,'測試店家','台北市羅斯福路1段1號','0222223333','Y','')")
cur.execute('select * from stores')
conn.commit()
for store in cur.fetchall():
print(store)
#print(cur.fetchall()[99])
cur.close()
conn.close()