[web2py] Re: How to select row based on item ID or name

2018-01-04 Thread Paul Ellis
You would still get a Rows Object though, even though there is only 1 row 
in it. 
You would need .first() .last() or [0] at the end to get just the row.
Or use the shortcut method.

db.table[id]



On Thursday, 4 January 2018 18:24:26 UTC+1, Dave S wrote:
>
>
>
> On Wednesday, January 3, 2018 at 10:48:32 PM UTC-8, Maurice Waka wrote:
>>
>>
>>
>>
>>
>>
>>
>> I have the following code for my DB:
>> dbmyhealth.define_table("health", 
>> Field('name', 'string'),
>> Field('definition', 'text', length= 100,),
>> Field('abnval', 'text', length= 100,),
>> Field('normval', 'text', length= 100,),
>> Field('administration', 'text', length= 
>> 100,),
>> Field('screening', 'text', length= 100,),
>> Field('causes', 'text', length= 100,),
>> migrate = False)
>>
>> rows  = dbmyhealth().select(dbmyhealth.health.ALL)
>> for row in rows: 
>> location0 = row.name
>> location1 = row.definition
>> location2 = row.abnvalinterpret
>> location3 = row.normvalinterpret
>> location4 = row.administration
>> location5 = row.screening
>> location6 = row.causes
>> corpus = [location1 , location2, location3, location4, location5, 
>> location6]
>>
>> I want to select an item, including all the fields from the abnval to the 
>> causes,not randomly but based on the ID or the name. If I use the limitby 
>> constraint,I can get either the first, second, or last item based on the 
>> selection used. If I use the below code, I get only the first item, which 
>> is everything based on obesity. I want to select any item with every query 
>> using either an ID or the names below e.g.
>> A code like: 
>> for row in rows:
>> if id == 2
>> code..
>>corpus = [location1 , location2, location3, location4, 
>> location5, location6]in this case my corpus will have everything on 
>> cardiomyopathy using the table details below.
>>
>> id name
>> 0. diabetes
>> 1. hypertension
>> 2. cardiomyopathy
>> 3. copd
>> 4. obesity
>>
>> So how do I code it to obtain my answer
>> Kind regards
>>
>>
> Wouldn't that be either of
>
>   rows = dbmyhealth(dbmyhealth.health.id == 2).select()
>
>
>
> or (if you were doing more with the query)
>
>   query = dbmyhealth.health.id == 2
>   rows  = dbmyhealth(query).select()
>
>
> ?
> (I didn't put in a first() because there's only 1 row with id == 2.)
>
>  http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query--Set--Rows
> >
>
> /dps
>
>

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


Re: [web2py] Re: How to select row based on item ID or name

2018-01-04 Thread Yoel Benítez Fonseca

You can get algo a row by ID by:

row = db.model_name(ID)

Where ID stand for the actual record id.

On Thu, Jan 4, 2018 at 1:13 PM, Maurice Waka  
wrote:

Second option is better for me

On 4 Jan 2018 8:24 PM, "Dave S"  wrote:



On Wednesday, January 3, 2018 at 10:48:32 PM UTC-8, Maurice Waka 
wrote:







I have the following code for my DB:
dbmyhealth.define_table("health",
Field('name', 'string'),
	Field('definition', 'text', length= 
100,),
	Field('abnval', 'text', length= 
100,),
	Field('normval', 'text', length= 
100,),
	Field('administration', 'text', 
length= 100,),
	Field('screening', 'text', length= 
100,),
	Field('causes', 'text', length= 
100,),

migrate = False)

rows  = dbmyhealth().select(dbmyhealth.health.ALL)
for row in rows:
location0 = row.name
location1 = row.definition
location2 = row.abnvalinterpret
location3 = row.normvalinterpret
location4 = row.administration
location5 = row.screening
location6 = row.causes
corpus = [location1 , location2, location3, location4, 
location5, location6]


I want to select an item, including all the fields from the abnval 
to the causes,not randomly but based on the ID or the name. If I 
use the limitby constraint,I can get either the first, second, or 
last item based on the selection used. If I use the below code, I 
get only the first item, which is everything based on obesity. I 
want to select any item with every query using either an ID or the 
names below e.g.

A code like:
for row in rows:
if id == 2
code..
   corpus = [location1 , location2, location3, location4, 
location5, location6]in this case my corpus will have 
everything on cardiomyopathy using the table details below.


id name
0. diabetes
1. hypertension
2. cardiomyopathy
3. copd
4. obesity

So how do I code it to obtain my answer
Kind regards



Wouldn't that be either of

  rows = dbmyhealth(dbmyhealth.health.id == 2).select()



or (if you were doing more with the query)

  query = dbmyhealth.health.id == 2
  rows  = dbmyhealth(query).select()


?
(I didn't put in a first() because there's only 1 row with id == 2.)



/dps

--
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/5DWqynKI_-g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
web2py+unsubscr...@googlegroups.com.

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 web2py+unsubscr...@googlegroups.com.

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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: How to select row based on item ID or name

2018-01-04 Thread Maurice Waka
Second option is better for me

On 4 Jan 2018 8:24 PM, "Dave S"  wrote:

>
>
> On Wednesday, January 3, 2018 at 10:48:32 PM UTC-8, Maurice Waka wrote:
>>
>>
>>
>>
>>
>>
>>
>> I have the following code for my DB:
>> dbmyhealth.define_table("health",
>> Field('name', 'string'),
>> Field('definition', 'text', length= 100,),
>> Field('abnval', 'text', length= 100,),
>> Field('normval', 'text', length= 100,),
>> Field('administration', 'text', length=
>> 100,),
>> Field('screening', 'text', length= 100,),
>> Field('causes', 'text', length= 100,),
>> migrate = False)
>>
>> rows  = dbmyhealth().select(dbmyhealth.health.ALL)
>> for row in rows:
>> location0 = row.name
>> location1 = row.definition
>> location2 = row.abnvalinterpret
>> location3 = row.normvalinterpret
>> location4 = row.administration
>> location5 = row.screening
>> location6 = row.causes
>> corpus = [location1 , location2, location3, location4, location5,
>> location6]
>>
>> I want to select an item, including all the fields from the abnval to the
>> causes,not randomly but based on the ID or the name. If I use the limitby
>> constraint,I can get either the first, second, or last item based on the
>> selection used. If I use the below code, I get only the first item, which
>> is everything based on obesity. I want to select any item with every query
>> using either an ID or the names below e.g.
>> A code like:
>> for row in rows:
>> if id == 2
>> code..
>>corpus = [location1 , location2, location3, location4,
>> location5, location6]in this case my corpus will have everything on
>> cardiomyopathy using the table details below.
>>
>> id name
>> 0. diabetes
>> 1. hypertension
>> 2. cardiomyopathy
>> 3. copd
>> 4. obesity
>>
>> So how do I code it to obtain my answer
>> Kind regards
>>
>>
> Wouldn't that be either of
>
>   rows = dbmyhealth(dbmyhealth.health.id == 2).select()
>
>
>
> or (if you were doing more with the query)
>
>   query = dbmyhealth.health.id == 2
>   rows  = dbmyhealth(query).select()
>
>
> ?
> (I didn't put in a first() because there's only 1 row with id == 2.)
>
>  database-abstraction-layer#Query--Set--Rows>
>
> /dps
>
> --
> 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/5DWqynKI_-g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> 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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How to select row based on item ID or name

2018-01-04 Thread Dave S


On Wednesday, January 3, 2018 at 10:48:32 PM UTC-8, Maurice Waka wrote:
>
>
>
>
>
>
>
> I have the following code for my DB:
> dbmyhealth.define_table("health", 
> Field('name', 'string'),
> Field('definition', 'text', length= 100,),
> Field('abnval', 'text', length= 100,),
> Field('normval', 'text', length= 100,),
> Field('administration', 'text', length= 
> 100,),
> Field('screening', 'text', length= 100,),
> Field('causes', 'text', length= 100,),
> migrate = False)
>
> rows  = dbmyhealth().select(dbmyhealth.health.ALL)
> for row in rows: 
> location0 = row.name
> location1 = row.definition
> location2 = row.abnvalinterpret
> location3 = row.normvalinterpret
> location4 = row.administration
> location5 = row.screening
> location6 = row.causes
> corpus = [location1 , location2, location3, location4, location5, 
> location6]
>
> I want to select an item, including all the fields from the abnval to the 
> causes,not randomly but based on the ID or the name. If I use the limitby 
> constraint,I can get either the first, second, or last item based on the 
> selection used. If I use the below code, I get only the first item, which 
> is everything based on obesity. I want to select any item with every query 
> using either an ID or the names below e.g.
> A code like: 
> for row in rows:
> if id == 2
> code..
>corpus = [location1 , location2, location3, location4, 
> location5, location6]in this case my corpus will have everything on 
> cardiomyopathy using the table details below.
>
> id name
> 0. diabetes
> 1. hypertension
> 2. cardiomyopathy
> 3. copd
> 4. obesity
>
> So how do I code it to obtain my answer
> Kind regards
>
>
Wouldn't that be either of

  rows = dbmyhealth(dbmyhealth.health.id == 2).select()



or (if you were doing more with the query)

  query = dbmyhealth.health.id == 2
  rows  = dbmyhealth(query).select()


?
(I didn't put in a first() because there's only 1 row with id == 2.)



/dps

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