Thanks, but I seem to be having a challenge when returning the rows from a
specific id name or number. I tried this on a different app as follows:
Model:
db.define_table( "health",
Field('name', 'string'),
Field('definition', 'text', length= 1000000, default="We'll
update soon.", notnull=True),
Field('abnvals', 'text', length= 1000000,default="We'll
update soon.", notnull=True),
Field('normvals', 'text', length= 1000000,default="We'll
update soon.", notnull=True),
def selections():
code
return name4# name4 is a list that contains items found in db.health.name,
as well as other dbs.
def refer11():
db = current.db
rows = db(db.health).iterselect()
for row in rows:
id = row.name
if id == item in name4:
#return [', '.join(item) for item in rows]# Gives a list of the titles only
as: ['name','definition','abnvals','normvals',]
#return [item for item in rows]# Gives this: [<row>
#return row# gives this : <row>
#return [item for item in row]# Gives a list of the
titles only as: ['name','definition','abnvals','normvals',]
When using sql speak, this works well:
def refer11():
id = 0
location = ""
conn = sqlite3.connect('wellness.db')
c = conn.cursor()
c.execute('select * from health')
records = c.fetchall()
for record in records:
id = record[1]
for item in name4:
if id == item in name4:
return record[2:]
If row.name has e.g. apple, mango, guava, pineapple, then
and the fields contain info about the fruits e.g.
if id/row.name picks mango, i want a list of these:
definition data: A mango is a fruit blah blah blah.
abnvals data: A mango when its green is bitter to taste.
normvals data: A mango when ripe looks bright yellow and tastes sweet.
so when doing return row
I should get ['A mango is a fruit blah blah blah. A mango when its green is
bitter to taste. A mango when ripe looks bright yellow and tastes sweet.]
and not
['name','definition','abnvals','normvals',]
On Fri, Apr 27, 2018 at 6:16 PM, Richard Vézina <[email protected]
> wrote:
> for f in db.table.fields:
> print f
>
> or
>
> rows = db(db.fruits.id > 0).select(db.fruits.ALL) # ALL means all fields
>
> for r in rows:
> print(r)
>
> You can control which field you want with the previous example
>
> myfields = [f for f in db.table.fields if SOME_FILTERING_CHECK_OVER_THE_
> FIELD_YOU_WANT]
>
>
> for r in rows:
> for f in myfields:
> print(r[f])
>
>
> You can play around that you should be able to figure out how you can do
> what you wanna do.
>
> Richard
>
> On Fri, Apr 27, 2018 at 10:08 AM, Maurice Waka <[email protected]>
> wrote:
>
>> Addendum
>>
>> I want a single list of the items (the data from all fields)
>>
>> regards
>>
>> On Fri, Apr 27, 2018 at 5:06 PM, Maurice Waka <[email protected]>
>> wrote:
>>
>>> There are several fields in my db such as this:
>>>
>>> db.define_table('fruit', Field('id', 'reference auth_user'),
>>> Field('apple','boolean',label=T('Apple')),
>>> Field('apricot','boolean',label=T('Apricot')),
>>> Field('cherry','boolean',label=T('Cherry')), Field('fig','boolean',
>>> label=T('Fig')), Field('lychee','boolean', label=T('Lychee')),
>>> Field('peach','boolean', label=T('Peach')), Field('pear','boolean',
>>> label=T('Pear')), Field('plum','boolean', label=T('Plum')))
>>> If i want to print items from a specific field i would do:
>>>
>>> rows = db(db.fruits)select()for row in rows:
>>> return row.apple
>>>
>>>
>>> Now I want to return all data from all fields. How Can i go about it.
>>>
>>> I have tried:
>>>
>>> return rows and I get a blank screen.
>>>
>>> return [rows] and I get [<rows>].
>>>
>>> Kind regards
>>>
>>> --
>>> 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 a topic in the
>>> Google Groups "web2py-users" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/web2py/-Hlx1yh-4MU/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> 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 [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/web2py/-Hlx1yh-4MU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.