Re: CakePHP 3.0 orm query question

2014-08-26 Thread Andras Kende
Hi Jose, I got it working as : $query = $this->find('all', array( 'limit' => 200, 'order' => array( 'distance' => 'ASC', 'name' => 'ASC', ),

Re: CakePHP 3.0 orm query question

2014-08-26 Thread José Lorenzo
$query = $table->find() $query->select(['distance' => $query->newExpr($rawSQL)])->having(['distance <=' => $distance]) On Monday, August 25, 2014 2:59:01 AM UTC+2, Andras Kende wrote: > > Hello, > > Im trying to convert this geolocator query from 2.5 to 3.0 orm but no luck > so far. > > CakePHP

CakePHP 3.0 orm query question

2014-08-24 Thread Andras Kende
Hello, Im trying to convert this geolocator query from 2.5 to 3.0 orm but no luck so far. CakePHP 2.5, this works fine: $results = $this->find('all', array( 'limit' => 200, 'order' => array( 'distance' => 'ASC', 'name' => 'ASC', ),

Re: Random query question

2011-05-20 Thread Sarpidon
Thank you guys. Going through your suggestions now. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send e

Re: Random query question

2011-05-19 Thread ShadowCross
If you are using MySQL as your database backend, read http://www.desilva.biz/mysql/random.html (found by Googling "mysql random row"). If you are not using MySQL, check if your database has a similar function. On May 19, 5:56 am, Sarpidon wrote: > Hi everybody. > > I have a companies table and

Re: Random query question

2011-05-19 Thread dreamingmind
one simple way would be to fetch all the records, then generate two non-equal random numbers in the range of found records, then pluck those two out of the result array. The returned records are numbered 0-10 in that array so it will be very simple to do! http://us.php.net/manual/en/function.rand.

Random query question

2011-05-19 Thread Sarpidon
Hi everybody. I have a companies table and those companies have promotions. Each company can have up to 10 promotions but only 2 can be displayed from each company at one time. I've been trying to figure out how to generate a single query that will select only 2 promotions randomly from each compa

habtm query question

2010-09-18 Thread Greg Skerman
Hi all, i'm trying to get a habtm query to work.. I've got the following models User (habtm Group) Group (habtm Group, hasmany Rule) Rule (belongs to Rule) Trying to get a list of rules for a given User - conditioning the query on Rule with User.id = $this->auth->user('id') but the user group

Re: Query question(s)

2010-06-10 Thread Ed Propsner
@John: I "think" I'm able to wrap my head around the concept. My project is extremely search heavy and if I'm following you correctly I can see a few distinct advantages to your system. What I like the most is being able to keep a history of searches within the session. I see a catastrophe just wa

Re: Query question(s)

2010-06-10 Thread John Andersen
I am using the DB to store the search criteria and the result. Not that the result creates more information, it creates only relationships between the stored search criteria and the existing records in other tables. The search is currently only based on one subject, either Article, Blog, Ebook, or

Re: Query question(s)

2010-06-10 Thread Ed Propsner
So I was a tad mistaken in my last post, displaying the tinyint data in user profiles didn't cut down on the code, it added a touch more but that's okay, it works just fine. ie. // SEEKING DATA $values = array(1,2,4,8,16,32,64); $storedValue = $user['Seeking']['seeking']; $seeking = array(); if(

Re: Query question(s)

2010-06-09 Thread Ed Propsner
@Calvin: I have very little experience with bitwise operations but if the concept was totally escaping me and you saw this don't ever be hesitant to tell me I'm being a dummy. I have no reservations with diving into a tutorial and picking up on something new. I never expect the answer but will alw

Re: Query question(s)

2010-06-09 Thread calvin
Manipulating bit fields can be confusing at times (e.g. on Monday it took me a while to realize the query in my original post didn't do what I thought it would), and there's usually more than one way to do it. But, basically, the way I approached it was to group all of the OR conditions together an

Re: Query question(s)

2010-06-08 Thread Ed Propsner
@Calvin: I do like the idea of using array_sum() and storing the options as an INT, I've taken this approach in the past with a different app (once) and it worked out just fine. In this case let's say you have a value of 3 stored in the db representing 2 options ... '1' => 'video, '2' => 'audio. A

Re: Query question(s)

2010-06-08 Thread John Andersen
This may not be relevant to your issue, but maybe to your solution. I will try to explain how I did my search functionality. In my application, the user will search for a specific object (Article, Author, Blog, etc.), not a combination of these. The search form provides the following entries: Wor

Re: Query question(s)

2010-06-07 Thread calvin
Ack, that example wasn't very good either, so let's try _one_ more time... Say you want to do a search for records that conform to these conditions: -must be of _both_ type Video AND Photo -must also be _either_ type Audio OR Text then $andOptions would be 5; $orOptions would be 10. On Jun 7, 7:

Re: Query question(s)

2010-06-07 Thread calvin
(My earlier post was inaccurate so I removed it. Let's try this again...) I don't think you need buildStatement() in this case as your query, although long, shouldn't actually be that complex, even if you end up with both OR and AND conditions. You just need to take a look at how OR/AND conditions

Re: Query question(s)

2010-06-07 Thread calvin
I don't think you need buildStatement() in this case as your query, although long, shouldn't actually be that complex, even if you end up with both OR and AND conditions. You just need to take a look at how OR/AND conditions are constructed in find() and then use them to build custom pagination que

Re: Query question(s)

2010-06-07 Thread Ed Propsner
@John: [quote] Can you explain why you have not separated/normalized the "SomeCol.contents"? And do you have other such columns in your database? [/quote] No, that is the only column in the db that stores multiple values in one field (that aren't for display only). At one point in time the data

Re: Query question(s)

2010-06-07 Thread calvin
If all of your search options are OR conditions, then you could theoretically do something like this: SELECT ... WHERE contents REGEXP '(opt1|opt2|opt3|opt4|opt5|opt6)'; http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp On Jun 6, 1:24 pm, Ed Propsner wrote: > I found a usable so

Re: Query question(s)

2010-06-07 Thread calvin
I'm not sure what you ought to do about the custom query (you may just have to build it the hard way or do as Ed suggest and redesign the DB), but regarding the URL, there are a few ways to go about it. Firstly, I should point out that the URL you wrote doesn't look right. Usually, with something

Re: Query question(s)

2010-06-07 Thread John Andersen
Based on what you have posted I would ask whether a redesign of the database would be a better idea! I refer to the issue you have created yourself, by having one column contain more than one value at the same time: [quote] ... The problem I'm running into is that $array can contain any number and

Re: Query question(s)

2010-06-06 Thread Ed Propsner
I found a usable solution, a bit exhaustive and long-winded perhaps, but usable nonetheless. I still need to put together a dynamic query and I'm finding myself avoiding having to do it at this time. I need to build a query dynamically based on what elements a user chooses from a form. There coul

Re: Query question(s)

2010-06-05 Thread Ed Propsner
Perhaps I'm over-complicating this but I'm still having some problems with building my query. I'm looking to do something like: $array = array (A, B, C, D, E); $list = implode( ',' , $array); 'conditions' => array( 'SomeCol.contents' => array($list)

Re: Query question(s)

2010-06-04 Thread Ed Propsner
Thanks Calvin, point well taken. I'll just stick with GET like I always have for searches. I tweaked the routing and got things cleaned up a bit so I guess I'm okay with it. I'm not quite sure what I was expecting in the first place? 8-) The search uses a lot of checkboxes and results in somethin

Re: Query question(s)

2010-06-04 Thread calvin
POST requests are generally not cached, but you can force it to be cached using the Cache-Control and Expires headers. However, I've never tried this so I don't know if the browser will still show the form submission dialog (it may need to resend the form data to check to see if the document has ch

Query question(s)

2010-06-04 Thread Ed Propsner
I was checking out the book on complex queries and not really finding what I'm looking for. I'm trying to create a query that covers both a basic and advanced search. The form may be submitting all or just some of the options available on the page depending on what the user chooses. Once the form

Re: Query question

2009-04-24 Thread brian
I don't think the number of characters in a query makes too much difference. Not compared to how the query is formulated, in any case. It's also not so much a Cake thing as between your DB and its PHP wrapper. But, again, it's likely the least thing to be concerned about. On Fri, Apr 24, 2009 at

Query question

2009-04-24 Thread Dave Maharaj :: WidePixels.com
Just doing some messing around on a site and playing with contain vs. $this->model->read($id). When I leave the controller to read the $id SQL Queries = 6 but contain spits out 8. Now the 6 queries was 2010 characters in length while the 8 queries was 400 less at 1600 characters. My question.

Re: Query question

2009-04-14 Thread Richard
You could possibly do a UNION query? If you need to know which table they came from, add a hard-coded value to the field list ('TableA' as which_table). SELECT id, firstname, lastname FROM tableA where email = 'a...@b.com' UNION SELECT id, firstname, lastname FROM tableB where email = 'a...@b.com'

Query question

2009-04-13 Thread Dave Maharaj :: WidePixels.com
I have come into a situation where I need to find something that will be in either TableA or TableB. Is there an easy way to do this or do i need to query TableA if no results query TableB? thanks, Dave --~--~-~--~~~---~--~~ You received this message because you

Complex Query Question

2009-03-28 Thread bakerLeo
I am stuck on a query problem : These are the tables involved : Group id name User id name Groups_Users (for HABTM) id group_id user_id Now i have an admin system that lets the admin view the group and all the related users. Which is working fine. However, I want to

Re: pagination / custom query question

2008-07-06 Thread Dardo Sordi Bogado
> I have 2 models Venue and Event. I want to do a search page that returns > both Venue and Event on 1 page and trying to get the ajax pagination feature > in cake rc2 to work. My advice is: Get it working without ajax, then add ajax. > However, the first parameter for $this->paginate(...) is th

pagination / custom query question

2008-07-06 Thread .
I have 2 models Venue and Event. I want to do a search page that returns both Venue and Event on 1 page and trying to get the ajax pagination feature in cake rc2 to work. However, the first parameter for $this->paginate(...) is the 'type' (model). Is it possible for my controller to have both $thi

Re: Query Question

2008-05-12 Thread grigri
// Controller $parks = $this->Skatepark->find('list', array( 'fields' => array( 'Skatepark.id', // Key path 'Skatepark.city', // Value path 'Skatepark.state' // Group path ), 'order' => 'Skatepark.city ASC, Skatepark.state ASC' ); $this->set(compact('parks')); // parks looks lik

Re: Query Question

2008-05-12 Thread Filip Camerman
I'd just use SELECT state, city FROM skateparks ORDER BY state, city Then loop it end everytime the state changes you print the state, otherwise just the city. On May 12, 12:39 pm, Kyle Decot <[EMAIL PROTECTED]> wrote: > They're not stored in separate tables. They're stored in my skateparks >

Re: Query Question

2008-05-12 Thread Sam Sherlock
look at self relating the table by using a field named parent_id if your baking cake will recognise that the relationship is a child/parent id | parent id | name | address | city | state ...etc 2008/5/12 Kyle Decot <[EMAIL PROTECTED]>: > > They're not stored in separate tables. They'r

Re: Query Question

2008-05-12 Thread Kyle Decot
They're not stored in separate tables. They're stored in my skateparks table which has: id | name | address | city | state ...etc --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to

Re: Query Question

2008-05-11 Thread Grant Cox
City belongsTo State Assuming Cake 1.2: $cities = $this->City->find('list', array('fields'=>array('City.id', City.name', 'State.name'), 'recursive'=>1) ); Then you can have a form select with cities as the data source, you should get exactly what you want. On May 12, 9:00 am, Kyle Decot <[EMAI

Query Question

2008-05-11 Thread Kyle Decot
I want to make a side nave bar with states and cities of that state as sub items. How would I write a query to do this? I want something like: Florida _Orlando _Daytona Ohio _Columbus _New Albany etc... Thanks as always for the help. --~--~-~--~~~---~--~~ You r

Re: Query Question

2008-04-02 Thread Dan
I figured it out $this->Game->bindModel( array('hasOne' => array( 'CategoriesGame' => array( 'className' => 'CategoriesGame' ) )),

Re: Query Question

2008-04-02 Thread Dan
Thanks for the note but I can't get conditions to work because it's a HABTM relationship. I tried $this->paginate('Game', "Category.name = 'puzzle'"); but it gives me SQL Error: 1054: Unknown column 'Category.id' in 'where clause' The query doesn't join Category to Game so it has no idea what

Re: Query Question

2008-04-02 Thread [EMAIL PROTECTED]
you set your conditions in the paginate variable. Example: class GamesController extends AppController { var $name = 'Games'; var $paginate = array( 'Game' => array( 'limit'=>10, 'order'=> 'Game.id ASC',

Query Question

2008-04-02 Thread dan
Games HABTM Categories I need to $this->paginate('Game'); where Category.name = 'puzzle' Is this possible? Tried using bindModel but can't figure it out. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP"

Re: newbie query question

2008-01-26 Thread Jeremi
Do you have? class Listing extends AppModel { public $belongsTo = array('Category'); } class Category extends AppModel { public $hasMay = array('Listing'); } Then you should be able to: $listing = $this->Listing->findAll(array('category_id' => $category_id)); On Jan 26, 9:30 pm, bob

newbie query question

2008-01-26 Thread bob
I have a Listings table and another Categories table, and Lists hasMany Categories. I am trying to write a cake query where it finds all lists in a certain category. $listings = $this->Listing->findAll( array('Category.category_id'=>$category_id) ); this returns an error. Also, if I do $this->Li

Re: hasMany query question

2006-11-19 Thread Nathan Garza
Thanks for the reply. Let me expand abit. Model 'A' hasMany 'B' and hasMany 'C'. I want to find the instance of model 'A' that has a spicific 'B' AND a specific 'C'. Now here's the part I left out. Model 'D' hasMany 'B' and 'E' hasMany 'C'. So, a given 'B' or 'C' belongs to only one 'A', but

Re: hasMany query question

2006-11-19 Thread [EMAIL PROTECTED]
Hmmm... Me thinks you have a logic problem. If "Classification belongsTo Ad " and "Location belongsTo Ad" then searching by both Location.id and Classification.id at the same time is redundant, since they would both share (at most) exactly one parent. So if "Classification belongsTo Ad ", then C

hasMany query question

2006-11-18 Thread naryga
Ok, I have 3 models: Ad, Classification, Location Ad hasMany Classification,Location Location belongsTo Ad Classification belongsTo Ad I want to be able to search for Ads based on the associated Classifications and Locations. I've tried using something like: $this->Ad->findAll("Classification.i