composite query

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

composite query

Bernard Grosperrin

I have 2 problems I need help with, but I will post 2 messages.

first: What would be the best way to have an interactive query?

I need to have users able to make a selection in 6 different columns, to
build a query with WHERE this and that (6 this and that..), knowing they
may select 1, or 2, or 3 or 4 or 5 or 6 values.

I would like to avoid making 36 ( 6* 6) elseif ....

Also, visually, I would like to have  this on he same page displaying
the data. Should it be a component, or can I have a form AND a view
simultaneously?

I am not working often enough with Cake to be fully fluent, so any help
will be greatly appreciated.

Bernard



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: composite query

cadraig

Bernard,

It sounds to me like you could use arrays, which may negate the need
for all of these elseif's that you describe...  maybe combined with a
foreach statement, building the query up inside there?

Your second point, I'm not sure I understand

- the html form will be displayed as part of the view.
- component - do you mean an element?  An element would be there to
reuse code in more than one page, (or more than once on a page.).

You could accept the data in a form, post back to the controller with
the data, perform the query and rerender the same page, populating the
previous empty table or whatever  with your newly selected data.
If you wanted you could do this through ajax and just populate a div
element or whatever without reposting back to the server but maybe you
want to take one thing at a time.

Hope this helps


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: [professionel] Re: composite query

Bernard Grosperrin

Tim
> It sounds to me like you could use arrays, which may negate the need
> for all of these elseif's that you describe...  maybe combined with a
> foreach statement, building the query up inside there?
>  
Thanks you, that make sense, I will look at this.

> Your second point, I'm not sure I understand
>
> - the html form will be displayed as part of the view.
> - component - do you mean an element?  An element would be there to
> reuse code in more than one page, (or more than once on a page.).
>
> You could accept the data in a form, post back to the controller with
> the data, perform the query and rerender the same page, populating the
> previous empty table or whatever  with your newly selected data.
>  
OK, that's the idea, what confuses me is that I would need to have 2
different functions in the controller, with the same view. I was under
the assumption that each function needs to be associated with her own
view. I am really still a beginner, so I would not be to surprised if I
was assuming something wrong....;-)
> If you wanted you could do this through ajax and just populate a div
> element or whatever without reposting back to the server but maybe you
> want to take one thing at a time.
>  
I thought of Ajax for this, but as you say, I am doing it a little step
at a time...

Bernard


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: composite query

cadraig

Hi Bernard,

There are many ways to skin a cat...

if you look at the Blog tutorial in the manual, there is the add()
function:

    function add()
    {
        if (!empty($this->data))
        {
            if ($this->Post->save($this->data))
            {
                $this->flash('Your post has been saved.','/posts');
            }
        }
    }

This is called initially with no params set.  This will fail the
(!empty($this->data) ) condition and render the view add.thtml (the
name of the function).  The user fills in the form and presses submit.
The form in this case will post back to the same function, but this
time the form will be populated with data.  The data will be saved (if
valid) and the flash statement redirects back to the index() page.

If you copy this functionality then you would not have 2 different
functions in the controller with the same view, only one.

If you didn't want the if() statement, you could post back to a
different function, eg. save( ) .  This could redirect on the flash
statement again, if valid.  If it fails validation then you could
render('add') which will force the add.thtml to be redisplayed, instead
of the default save.thtml (which does not exist).

Hope this helps


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---