SQLite Forum

SELECT using variables
Login
Hi...

I have a table with following columns (author, title, body)

I am trying to implement a tag system, clicking a tag should retrieve all posts that have this tag.

my python code is as follows:

def get_posts(name, tag):
    posts = get_db().execute(
        'SELECT * FROM post WHERE (? = ?) ORDER BY created DESC', (name, tag)
    ).fetchall()

name is a variable for a column
tag is the value assigned to name.

But it won't work

Some suggested:
def get_posts(name, tag):
    posts = get_db().execute(
        'SELECT * FROM post WHERE ('+ name +' = ?) ORDER BY created DESC', (tag,)
    ).fetchall()

but won't work too... 

What am I doing wrong???