Advertisement
afrizalwahyuadi66

mysql-search.py

Dec 18th, 2024 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. import mysql.connector
  2.  
  3. db = mysql.connector.connect(host="localhost",
  4.                              user="root",
  5.                              password="", database="db112300xx")
  6.  
  7. cursor = db.cursor()
  8.  
  9. while(True):
  10.     npm=input("Input NPM: ")
  11.     val=(npm,)
  12.  
  13.     sql = "SELECT * FROM tblmahasiswa WHERE npm_mhs=%s"
  14.     cursor.execute(sql,val)
  15.     results = cursor.fetchall()
  16.  
  17.     if(cursor.rowcount==0):
  18.         print("Record tidak ada/ditemukan...")
  19.     else:
  20.         for data in results:
  21.             print(f"Nomor Record : {data[0]}\n"
  22.                   f"NPM Mahasiswa : {data[1]}\n"
  23.                   f"Nama Mahasiswa : {data[2]}\n"
  24.                   f"Jenis Kelamin (P/L) : {data[3]}\n"
  25.                   f"Program Studi (SI/IF): {data[4]}\n")
  26.     ulang=input("Ulangi pencarian data? (y/t) ").lower()
  27.     if(ulang!="y"):
  28.         break
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement