Hi I am sending the code of the function "searchbyemail" and the output of the program when I run I am trying to search and display the results , even if we give a part of the email_id thanks Joseph John
**************** SEARCH by email _id function ******************************** ################################################################################ def searchbyemail(): s_email = raw_input("Enter the Email to be searched ") db = MySQLdb.connect(host="localhost",user = "john", passwd = "asdlkj", db = 'learnpython') entry = db.cursor() entry.execute("""SELECT * FROM contact WHERE email_id = %s """, (s_email,)) p = entry.fetchall() print p ####################################################################### *** Output of the short run ********* [EMAIL PROTECTED] experiement]$ python mysqlentry.py Data Base Entry for the Testing Env 0 - Quit 1 - Enter the Data 2 - Display The data 3 - Search The Company 4 - Delete Some info Choice :........2 (('Joseph', '[EMAIL PROTECTED]', '1234', '4321'), ('John', '[EMAIL PROTECTED]', '4567', '7654'), ('CityBank', '[EMAIL PROTECTED]', '987', '789'), ('ABN amro', '[EMAIL PROTECTED]', '456', '654')) Data Base Entry for the Testing Env 0 - Quit 1 - Enter the Data 2 - Display The data 3 - Search The Company 4 - Delete Some info Choice :........3 Do U want to search by Name , email id , phone or fax U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice :........2 Enter the Email to be searched [EMAIL PROTECTED] (('ABN amro', '[EMAIL PROTECTED]', '456', '654'),) U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice :........2 Enter the Email to be searched loan () U want to search the contacts by 0 - Quit 1 - Name 2 - email_id 3 - phone 4 - fax Choice :........ --- Kent Johnson <[EMAIL PROTECTED]> wrote: > John Joseph wrote: > > Hi > > Thanks to Allan,Danny,Pujo > > I did my simple python script for MySQL , > the > > scripts add the data , and search for the data and > > display > > I have problem in searching email id > ,ie > > If search for the [EMAIL PROTECTED] , I will not get > any > > result , Guidance and advice needed for the > reason > > for this behavior > > Does it work when you search for other data such as > name or phone? > > Can you show the output from a short run where you > add a contact, > display the data and search for an email? > > Kent > > > I had added my script in this mail > > Thanks > > Joseph John > > > > > ********************************************************* > > > > """ This program is for to learn > > how to enter data to MySQL using python > > How to search > > not using OOP > > > > Have problem in searching email-id > > Why I do not get correct results when > > searching email id > > "@" string search containg "@" gives empty > > results > > > > """ > > > > > > > > import MySQLdb > > > > def selecter(): > > choice = None > > while choice != "0": > > print \ > > """ > > Data Base Entry for the Testing Env > > 0 - Quit > > 1 - Enter the Data > > 2 - Display The data > > 3 - Search The Company > > """ > > choice = raw_input("Choice :........") > > print > > > > if choice == "0": > > print "Good Bye ..." > > elif choice == "1": > > dataentry() > > > > elif choice == "2": > > datashow() > > elif choice == "3": > > datasearch() > > > > > > > > def dataentry(): > > name = raw_input("Enter the name of the company > ") > > email_id = raw_input("\n Enter the email ID : ") > > phone_no = raw_input("Enter the Phone No : ") > > fax_no = raw_input("\n Enter the fax no : ") > > > > db = MySQLdb.connect(host="localhost",user = > "john", > > passwd = "asdlkj", db = 'learnpython') > > entry = db.cursor() > > #entry.execute("""INSERT INTO contact > > """,(name,email_id,phone_no,fax_no,)) > > entry.execute("""INSERT INTO > > contact(name,email_id,phone_no,fax_no) VALUES > > (%s,%s,%s,%s)""",(name,email_id,phone_no,fax_no,)) > > print name , email_id , fax_no, phone_no > > > > > > > > > > def datashow(): > > db = MySQLdb.connect(host="localhost",user = > "john", > > passwd = "asdlkj", db = 'learnpython') > > entry = db.cursor() > > entry.execute("SELECT * from contact") > > p = entry.fetchall() > > print p > > > > def datasearch(): > > print "Do U want to search by Name , email id , > phone > > or fax " > > choice = None > > while choice != "0": > > print \ > > """ > > U want to search the contacts by > > 0 - Quit > > 1 - Name > > 2 - email_id > > 3 - phone > > 4 - fax > > """ > > choice = raw_input("Choice :........") > > print > > > > if choice == "0": > > print "Good Bye ..." > > elif choice == "1": > > searchbyname() > > > > elif choice == "2": > > searchbyemail() > > > > elif choice == "3": > > searchbyphone() > > elif choice == "4": > > searchbyfax() > > > > def searchbyname(): > > s_name = raw_input("Enter the name to be searched > ") > > db = MySQLdb.connect(host="localhost",user = > "john", > > passwd = "asdlkj", db = 'learnpython') > > entry = db.cursor() > > entry.execute("""SELECT * FROM contact WHERE name > = > > %s""", (s_name,)) > > p = entry.fetchall() > > print p > > > > def searchbyemail(): > > s_email = raw_input("Enter the Email to be > searched > > ") > > db = MySQLdb.connect(host="localhost",user = > "john", > > passwd = "asdlkj", db = 'learnpython') > > entry = db.cursor() > > entry.execute("""SELECT * FROM contact WHERE > email_id > > = %s""", (s_email,)) > > p = entry.fetchall() > > print p > > > > > > def searchbyphone(): > > s_phone= raw_input("Enter the Phone no to be > > searched ") > > db = MySQLdb.connect(host="localhost",user = > "john", > > passwd = "asdlkj", db = 'learnpython') > > entry = db.cursor() > > entry.execute("""SELECT * FROM contact WHERE > phone_no > > = %s""", (s_phone,)) > > p = entry.fetchall() > > print p > > > > > > > > def searchbyfax(): > > s_fax = raw_input("Enter the FAX no to be > searched > > ") > > db = MySQLdb.connect(host="localhost",user = > "john", > > passwd = "asdlkj", db = 'learnpython') > > entry = db.cursor() > > entry.execute("""SELECT * FROM contact WHERE > fax_no = > > %s""", (s_fax,)) > > p = entry.fetchall() > > print p > > > > selecter() > > > > > > > > > > > > > ___________________________________________________________ > > === message truncated === ___________________________________________________________ To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor