Hey guys, im new to Web2Py AND python ... my goal was to learn python while i move a site i did in php to web2py and im almost finishing :D
Im stuck a bit with ajax and partial queries , im going to detail a bit what i mean about partial queries. I have a field in the DB that has multiple text (yeah thats not relational definition) ... imagine i have a field called Name where i store the full name of a person. First Name , Second Name, Surname , Second Surname, etc.. What i want is to live search with ajax that DB field so if i write the first name it matches and second name also, and so on. What i did for that an array splitted by spaces and then what i need is a way i can use AND with LIKE ... the way i saw in the documentation (db.Table.name.like('%array[0]%''))&(db.Table.name.like ('%array[1]%'')) is not working for me.. im using ajax the same way i use it for PHP not using the ajax html file is providen.. im using my own files. I have to say its working without the AND so it works for the first name pretty well :-) . I will share my code commented because i write some part in spanish. def ajaxlivesearch(): resultadoParcial = request.vars.values()[0] #I store the partial result the user is typing on the textbox array_resultadoParcial = resultadoParcial.split(' ') # i split with spaces and store in a list / array #so if the user type his first name.. the array has 1 item or none and this works like a charm if len(array_resultadoParcial) <= 1: query = db.Paciente.nombre.like('%'+array_resultadoParcial[0]+'%') else: #if the array has more items i will iterate it but i need to use the AND to "join" every iteration for index in range(0,len(array_resultadoParcial)-1): query = query & db().Paciente.nombre.like('%'+array_resultadoParcial [index]+'%') pacientes = db(query).select(db.Paciente.nombre,limitby=(0,7)) j = 0 retorno = [] for paciente in pacientes: #i iterate into the query result object and return a list of data retorno.append('<div id="resultLiveSearch"><a href="#" id="res'+str (j)+'" onclick="copyToBox(document.getElementById(\'res'+str(j) +'\').innerHTML)">'+paciente.nombre+'</a></div>') j+=1 return retorno Thanks in advanced :-)
-- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.