すべてのアカウントを表示するWebページがあります。その下には、バランス欄に応じてテーブルに特定の行をハイライト表示させるオプションがあります。私の質問は、if
ステートメントを作成することができます。最初の行には、より大きい、等しい、等のオプションを含む変数のみが含まれています。 オリジナルの設定では、>
、>=
、=
、<=
、または<
が必要な場合はドロップダウンメニューから選択し、次に2番目の部分は金額に入れます。私はif
ステートメントは、私は彼らがオペレータを選択するためのオプションが好きではないと思います。ここでPythonのIF文の先頭に3つの変数を使用
は私のWebページの一部を形成するためのコードです:
import cgi, cgitb, sqlite3
cgitb.enable()
sqlite_file="C:\\Users\\U49228\\Desktop\\Class exercises\\Banking.sqlite"
connect=sqlite3.connect(sqlite_file)
cursor=connect.cursor()
form=cgi.FieldStorage()
bal=int(form.getvalue('bal'))
opt=form.getvalue('option')
print("Content-type:text/html\r\n\r")
print()
print("<html>")
#Header
print("<head>")
print("<title>View Accounts Functions</title>")
print("</head>")
#body
print("<body bgcolor=#d4f4b0>")
#table
print("<center>")
print("<table border=2>")
print("<th>Acct_No</th>")
print("<th>Name</th>")
print("<th>Balance</th>")
def high_bal():
cursor.execute("Select * from Banking_Accounts")
all_rows=cursor.fetchall()
for row in all_rows:
accno=row[0]
cname=row[1]
amt=int(row[2])
if amt opt bal:
print("<tr bgcolor='cornsilk'>")
else:
print("<tr>")
print("<td>"+str(accno)+"</td>")
print("<td>"+cname+"</td>")
print("<td>"+str(amt)+"</td>")
print("</tr>")
print("</table>")
print("</center>")
#end table
print("<br><BR>")
print("<center>")
print("<a href='http://localhost:8000/cgi-bin/Bank_Menu.py' style=color:black>Return to Main Menu</a>")
print("</center>")
print("</body>")
print("</html>")
私は機能ページをインポートするには、計画:
#form
print("<form action='http://localhost:8000/cgi-bin/Bank_ViewAll.py'>")
print("<center>Highlight rows based on balance amounts!</center>")
print("<BR><BR>")
print("<center>Balance: ")
print("<select name='option' style=background:#eef9a0> $")
print("<option value='""' style=background:#eef9a0>Choose an Option</option>")
print("<option value='>' style=background:purple>Greater Than (>)</option>")
print("<option value='>=' style=background:blue>Greater Than or Equal To (>=)</option>")
print("<option value='=' style=background:yellow>Equal To (=)</option>")
print("<option value='<' style=background:orange>Less Than (<)</option>")
print("<option value='<=' style=background:red>Less Than or Equal To (<=)</option>")
print("</select>")
print("<input type='text' size='15' name='bal' style=background-color:#eef9a0>")
print("<br><BR>")
print("<center>")
print("<input type='submit' class='buttonStyle' value='Submit'> ")
print("<input type='reset' class='buttonStyle' value='Clear fields'>")
print("</center>")
print("</form>")
#end form
そして、ここでは私の関数のコードです。私は関数内の変数(def high_bal(opt,bal)
)を追加しようとしただけでなく、onClick
を送信ボタンに、onSubmit
をフォーム上に試してみました。また、フォームを関数ページにリダイレクトし、関数名を削除して、先に進むページにリダイレクトし、呼び出さずに関数を実行するようにしました。私のWebページデザインの
スクリーンショット:
スペクタキュラーを!これは私のために働いた!どうもありがとうございます! – Tigger