That is because this line
  userstuff=db(db.user_extended.userinfo ==
      db.product.userinfo).select(db.user_extended.ALL)
is just a join of table user_extended to table product on userinfo
from both tables.

The join will return the same information every time you query no
matter what product_id goes into the page request args because there
is no where condition to limit the selection. You need another
condition to isolate the specific row you want from user_extended.

I would try to just use a single db call with joins to put the tables
together
e.g.
user_products = db((db.product.id == this_page) &
                   (db.product.id == db.product_extended.product) &
                   (db.product.userinfo ==
db.users_extended.userinfo)).select()

The first condition selects the right product based on the input
parameter to the page, the second condition joins product to
product_extended, the third condition joins product to users_extended.

Now you don't need the zip, the database did the work plus the join
will associate the users_extended info to the product info using the
common foreign key userinfo from both tables which is set to
db.auth_user.id on record creation in both cases. The empty select()
brings back all columns of the join which may be inefficient but you
can name the required columns in a comma separated list to be more
specific.

Process it with

{{for row in user_products:}}
{{=row.users_extended.country}}
{{=row.product.category}}

I might have the row.table.field wrong, just print the row once and
look at the console output to see how to extract if this part doesn't
work.

Ron

On Oct 13, 5:27 pm, Andrew Evans <[email protected]> wrote:
> Hello ty for replying
>
> this is the function
>
> def indv_product():
>     this_page = request.args(0)
>     product=db(db.product.id == this_page).select(db.product.ALL)
>     product_e=db(db.product_extended.product ==
> this_page).select(db.product_extended.ALL)
>     userstuff=db(db.user_extended.userinfo ==
> db.product.userinfo).select(db.user_extended.ALL)
>     return dict(product=product,product_e=product_e,userstuff=userstuff)
>
> I use a link
>
> {=A(row.product_name,
> _href=URL('display', 'indv_product', args=row.id))}}
>
> then call the values of data
>
> {{for stuff, products in zip(userstuff, product):}}
>
> {{=stuff.country}}
>
> {{=products.category}}
>
> the value passed to products but the values being passed to stuff return the
> first entry in the db not sure what I am doing wrong cause I had it working
> before
>
> Maybe not...
>
> Cheers on the advice :D
>
> On Wed, Oct 13, 2010 at 11:46 AM, mdipierro <[email protected]> wrote:
> > I think you want this:
>
> > product= db.product(this_page)
> > userstuff=db(db.user_extended.userinfo==product.userinfo).select()
>
> > But I am not sure. Can you explain us more?
>
> > On Oct 13, 11:13 am, Andrew Evans <[email protected]> wrote:
> > > How can I make these two queries into one cause when I use them in my
> > view
> > > (htmll) it doesn't work as expected
>
> > > product=db(db.product.id == this_page).select(db.product.ALL)
>
> > > userstuff=db(db.user_extended.userinfo ==
> > > db.product.userinfo).select(db.user_extended.ALL)
>
> > > this is what I am doing
>
> > > {{for stuff, products in zip(userstuff, product):}}
>
> > > if anyone has suggestions on how I can get this to work. Currently the
> > user
> > > stuff value always returns the first entry in the db regardless of which
> > > user I select
>
> > > Any ideas
>
> > > *cheers
>
> > > Andrew
>
>

Reply via email to