[Tutor] Searching for email id in MySQL giving wrong results

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Jan 29 09:59:44 CET 2006



On Sun, 29 Jan 2006, John Joseph wrote:

>    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

Hi John,

Ok; because the question you're asking looks a little homework-y, we have
to be a little bit more cautious in our answers.  What part are you
getting stuck on?


Do you understand how SQL wildcards work?  There's a good number of SQL
tutorials on the web.  For example, we can take a look at the queries
section on Phil Greenspuns "SQL for Web Nerds" page:

    http://philip.greenspun.com/sql/queries.html

(In fact, the examples he uses to talk about wildcards there seems very
pertinant to your question!)


Or are you getting stuck about constructing such a query using string
operations?  If so, you might find something like:

    http://diveintopython.org/native_data_types/formatting_strings.html

useful.


If you can give us more details on where you're having difficulty, we'll
try to point you in a good direction.


One suggestion about the code: you may also want to look into making the
helper functions that use parameters, so you can more easily test it out
on different examples.

For example, if we have a program like:

######################################
def howTallProgram():
    n = raw_input("how tall are you?")
    if n < 3:
        print "small"
    elif n < 6:
        print "medium"
    else:
        print "tall"
######################################

then this can be broken out into a helper function to take a height get a
description of that height:

######################################
def describeHeight(n):
    if n < 3:
        return "small"
    elif n < 6:
        return "medium"
    else:
        return "tall"
######################################

which is fairly easy to test from the interactive interpreter.


The programs that you've shown us so far seem to emphasize direct printing
and interacting with the user.  You may find functions more useful by
making them take inputs and returning outputs.


Best of wishes to you!



More information about the Tutor mailing list