start with:

def cost3():
    jnum = request.args(0,cast=int)
    a = 0
    results = db(db.PO.job_id==jnum).select()
    for row in results:

        a = a + row.mycost
    return dict(a=a, howmany=len(results))



so you can check how many rows are you actually selecting :P


On Sunday, January 4, 2015 4:17:03 AM UTC+1, Greg White wrote:
>
> I am brand new to web2py and know a little python, so I am a definite 
> novice. I am trying to build a purchasing agent app and am getting result 
> "0" from function cost3. I am expecting to get a sum of the values for a 
> specified job number (in cost2) in table PO Field mycost when I specify a 
> job number in function cost2.. but I am not getting a sum of those numbers 
> but am getting 0 instead. Any help would be appreciated, thanks.
>
> db
>
> db.define_table('jobinfo',
>     Field('jobnumber', 'integer', requires=IS_NOT_EMPTY()),
>     Field('jobname', 'string', requires=IS_NOT_EMPTY()),
>     Field('jobbudget', 'double'),
>     format = '%(jobnumber)s')
>
> db.define_table('vendortype',
>     Field('vtype', 'string', requires=IS_NOT_EMPTY()),
>     format = '%(vtype)s')
>
> db.define_table('vendorr',
>     Field('company_name',requires=IS_NOT_EMPTY()),
>     Field('address1',requires=IS_NOT_EMPTY()),
>     Field('address2'),
>     Field('city',requires=IS_NOT_EMPTY()),
>     Field('co_state',requires=IS_NOT_EMPTY()),
>     Field('zip',requires=IS_NOT_EMPTY()),
>     Field('vendor_type', db.vendortype),
>     Field('terms'),
>     format = '%(company_name)s')
>
> db.define_table('POreq',
>     Field('job_id', db.jobinfo, requires=IS_NOT_EMPTY()),
>     Field('Vendor_id', db.vendorr, requires=IS_NOT_EMPTY()),
>     Field('Qty_1'),
>     Field('Description_1'),
>     Field('Notes_1'),
>     Field('RequiredBy_1','date'),
>     format = '%(Vendor_id)s')
>
> db.define_table('PO',
>     Field('job_id', db.jobinfo ),
>     Field('vname',db.vendorr),
>     Field('Qty_1', 'double'),
>     Field('Description_1'),
>     Field('Notes_1'),
>     Field('RequiredBy_1','date'),
>     Field('mycost', 'double'),
>     format = '%(job_id)s')
>
> controller
>
> def cost2():
>     form=FORM('Job Number: ',
>         INPUT(_name='jobnumber', requires=IS_INT_IN_RANGE(0,9000)),
>         INPUT(_type='submit')).process()
>     if form.accepted:
>         redirect(URL('cost3',args=form.vars.jobnumber))
>     return dict(form=form)
>
> def cost3():
>     jnum = request.args(0,cast=int)
>     a = 0
>     for row in db(db.PO.job_id==jnum).select():
>         a = a + row.mycost
>     return a
>
>

-- 
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.

Reply via email to