python & mysql probelm

wes weston wweston at att.net
Fri Mar 26 22:20:49 CET 2004


james blair wrote:
> Hi
> I am having a problem executing following query:
> cursor.execute("select * from projects where projectid between '%s'
> and '%s'"%(id1,id2))
> But say if i have projectid's from 1 to 20 in database & if i give the
> project range 1 to 2 then it gives me the result 1,2,11,12,13,14.....
> When I execute this query in mysql i.e
> select * from projects where projectid between 1 and 2,I get the
> correct result.
> I also tried doing 
> cursor.execute("select * from projects where projectid between '%s'
> and '%s'"%(int(id1),int(id2))
> but no success
> What should I do??
> Regards,
> James

James,
    As strings 11 is less than 2. Are your fields strings
or ints? If you change them from strings to ints, mysql
will make the translation.
wes




More information about the Python-list mailing list