I have been working on this pset for two weeks now and cannot figure out the search function. (I skipped it and moved on) I have no idea why this function is not working or if it is working just my other code is wrong.

When I use the link to check your function in the specification (https://ide50-username.cs50.io/search?q=02138) I am returned an empty set --> [ ]. I cannot figure out why and I have tried everything!!

Here is my code:

def search():
"""Search for places that match query."""

# get q
q = request.args.get("q") + "%"

#select q from table
place = db.execute("SELECT * FROM places WHERE postal_code LIKE :q", q=q)

#reuturn results -- TEN MAX
if len(place) > 10:
    return jsonify([place[0], place[1], place[2],place[3], place[4], place[5], place[6], place[7], place[8], place[9]])
    return jsonify(place)

UPDATE: I imported the database with the commands shown in the specification.

$ sqlite3 mashup.db
.separator "\t"
.import US.txt places

I currently have places as a table in mashup. Here is a screenshot of what it looks like:

enter image description here

Does this look correct?

1 Answer 1


Possible explanation 2: The places table is not populated in the database that the web server accesses (specifically mashup.db in the mashup directory). Have you tried the query with phpliteadmin or sqlite3? It's fairly easy to create multiple databases, since phpliteadmin (and sqlite3) will create a new database if the named db does not exist.

A possible explanation is postal_code is a NUMERIC type in the database. If it is not TEXT, this query SELECT * FROM places WHERE postal_code LIKE :q" will return no rows.

From the sqlite doc (emphasis added):

The operand to the right of the LIKE operator contains the pattern and the left hand operand contains the string to match against the pattern.

  • Thanks, but I do have postal_code as type TEXT. Is there anything else you suggest? Aug 10, 2017 at 16:42
  • added suggestion to answer. Aug 10, 2017 at 20:38
  • I updated my question with my phpLiteAdmin info, but I could not figure out how to use the query for my code. Thanks for the help! Aug 12, 2017 at 10:14
  • I figured it out! Thanks for the help!!! Aug 12, 2017 at 10:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .