Ok this is what i am trying to achieve and have been struggling with for weeks now, in the controller below I am searching for businesses that offer desired services, after displaying all those businesses, from that very list am trying to further filter through that list by searching for businesses that offer that desired service but in a certain desired location. I hope I give sense
*FULL CONTROLLER1 CODE* def companies(): *resultsARE=db.services(request.args(0))* rslts=db(db.business.services==resultsARE.id).select(db.business.ALL, orderby=db.business.company_name) services=len(rslts) form=SQLFORM.factory(Field('query', requires=IS_NOT_EMPTY(), label=SPAN( '', _style="font-weight: bold;"), widget = lambda field, value: SQLFORM. widgets.string.widget(field, value, _class='my-string', _id='searching', _placeholder='LOCATION'))) searchBtn=form.element('input',_type='submit') searchBtn['_style'] = 'display:none;' if form.accepts(request): tokens=form.vars.query.split() query=reduce(lambda a,b:a&b, [db.locations.name.contains(k) for k in tokens]) location=db(query).select(orderby=db.locations.name) else: location=[] return locals() *CONTROLLER2 CODE* def Results(): results=db.locations(request.args(0)) comps=companies() for services in comps: serv=services rslts=db(db.business.place==results.id).select *(db.business.services==resultsARE.id)* services=len(rslts) return locals() Mostwanted On Wednesday, March 27, 2019 at 8:42:30 PM UTC+2, Anthony wrote: > > It's not quite clear what you mean. Are these two functions two separate > controller actions? If so, it's not clear how you can share that variable, > as it is defined based on request.args(0) in the first function, but > presumably request.args(0) has a different meaning in the context of the > second function. What are you really trying to do? > > On Wednesday, March 27, 2019 at 8:11:15 AM UTC-4, mostwanted wrote: >> >> I have 2 functions and i want to use the value of the variable returned >> by one function in another function, how can i achieve this? >> I want to use the value of *resultsARE *in *function1 *in the same way >> in *function2 *as attempted in the highlighted lines below. >> >> *FUNCTION1* >> def companies(): >> *resultsARE=db.services(request.args(0))* >> rslts=db(db.business.services==resultsARE.id).select(db.business.ALL, >> orderby=db.business.company_name) >> services=len(rslts) >> return locals() >> >> *FUNCTION2* >> def Results(): >> results=db.locations(request.args(0)) >> comps=companies() >> for services in comps: >> serv=services >> rslts=db(db.business.place==results.id).select >> *(db.business.services==resultsARE.id)* >> services=len(rslts) >> return locals() >> Mostwanted >> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.