cakephp find method not working - cakephp

I know this is very silly question but here I am not getting any error.
Bellow query working fine
$data=$this->Test->query('SELECT * FROM tests where report_id=85');
But same query in find method are not working
$condition=array('Test.report_id'=>85);
$data=$this->Test->find('all',array('condition'=>$condition));

find statement in cakephp should be
$condition=array('Test.report_id'=>85);
$data = $this->Test->find('all',array('conditions'=>$condition));

Cakephp find statement error in 'codintion'
You should try this
$data=$this->Test->find('all',
array('conditions'=>
array('Test.report_id'=>85)
)
);
please replace condition to conditions

You made Typo.And lets understand why 's' is used.
There can be 100 conditions in an array , Not only one , so its conditions
$conditions=array('Test.report_id'=>85);
$data = $this->Test->find('all',array('conditions'=>$conditions));
And another thing -> Always use $conditions as variable naming convention because you never know there are 1,2, or 1000 conditions .

Related

array_search returns just 1 result

I´m starting to study PHP and I have a doubt in one lesson about array_search.
The teachers example shows "A peeple who got a 10" and as only one of the people got a 10 everything works fine, showing the person's name.
But I've been trying to use it to fetch more than one result. In this case I created this array, with 3 people taking 10:
$notas2=array(
"Ana"=>4,
"Misca"=>10,
"Chatuba"=>6,
"Jurandir"=>7,
"Musca"=>10,
"Mickey Mouse"=>10,
);
echo array_search(10,$notas2);
This code just returns "Misca". I tried a foreach, but it returned only "MiscaMiscaMiscaMiscaMiscaMisca". lol
foreach(array_search(10,$notas2)as $tirou10){
echo $tirou10;
}
Anyone can help-me?
Tanks.
array_search will export only first corresponding key. If you want to get all people who got 10 use array_keys($notas2, 10) it will return array and instead of echo use var_dump() or var_export()
The PHP function array_search only returns the first entry.

Using Google Sheet's Filter function, clarification needed

I am trying to filter some information with 2 conditionals (something is true and something else is >0)
Independently things work just fine:
=unique(filter(
indirect($A$1&"!$E$3:E"),
indirect($A$1&"!$C$3:C")=TRUE
))
gives me a list of things that are true, and
=unique(filter(
indirect($A$1&"!$E$3:E"),
indirect($A$1&"!$J$3:J")>0
))
gives me a list of things that are >0.
When i try to combine them, like this
=unique(filter(
indirect($A$1&"!$E$3:E"),
indirect($A$1&"!$C$3:C")=TRUE,
indirect($A$1&"!$J$3:J")>0
))
I get an error No matches are found in FILTER evaluation.
What am i missing please?
PS: It goes without saying that I do indeed have things that are both true and are > 0
for non-english locale it would be:
=unique(filter(
indirect($A$1&"!$E$3:E");
indirect($A$1&"!$C$3:C")=TRUE;
indirect($A$1&"!$J$3:J")>0))

Can I use same param name multiple times in the URL for codeigniter-restserver?

http://example.com/api/transfer/transfers/code/456/code/234
When using $this->get('code') on a url like above I expect the REST library to return an array or a list of the codes.
Instead it returns the last one.
Is there a way to return both values in a list, or is there another recommandation for formating the URL.
Thank you
I know it has been long since you posted the question. However it could help other people looking for the same thing.
Assuming that transfer is your controller and transfers is the function, another way to format your url could be:
http://example.com/api/transfer/transfers?code[]=456&code[]=234
This was you perform $this->get('code') you'll get an array back.
If you are creating the url via code then you may use http_build_query(). It handles the necessary escaping. It means it will replace [ for %5B and ] for %5D, in this case.
The code would be like:
$codes = array(456, 234);
$query = http_build_query(array('code' => $data));
$url = 'http://example.com/api/transfer/transfers?' . $query;

Foreach loop involving $date Variable CAKEPHP

I'm new to cakephp and I'm trying to write a for each loop that will get each event that is less than or equal to (<=) today's date.
First of all I'm not really sure if a for each loop is the best way to go about this, I have also been considering a while loop or an if statement but I don't know how else to get each entry from the database.
So here's where I've got to so far.
DATABASE HEADINGS
<?php foreach ($events['Event']['startDate'] <= $date): ?>
DATABASE RESULTS
Unfortunately I receive the following error:Parse error: syntax error, unexpected ')' in /homepages/3/d439567456/htdocs/cakephp/app/View/Events/live.ctp on line 22 (which is the for each loop line.
Any help would be great thanks and examples would be appreciated!
you cannot just change how PHP works.
Usually, events also have a numeric index for more than one "Event".
foreach ($events as $event) {
if ($event['Event']['startDate'] <= $date) {} else {}
}
To access a specific startDate directly, e.g. the first, you would need 0 as key:
if ($events[0]['Event']['startDate'] <= $date) {} else {}
But you cannot abuse foreach this way, though.

Order the result of findDependentRowset does not work

I'm using the findDependentRowset() of the Zend-Framework. Here, I want to define some selection settings like ORDER or LIMIT.
The examplecode I've found doesn't work at all for me :-(
$table = new MyTable(); // extends Zend_Db_Table
$row = $table->fetchAll()->current();
$rowset = $row->findDependentRowset(
'table',
$table->select()->order('von ASC')->limit(1)
);
First thing is, that the select() method is not defined here. I have to use getAdapter() to be able to use this method.
Next, I get a warning:
No reference rule "SELECT ORDER BY `von` ASC LIMIT 1"
How can I fix this?
Thank you very much!!
Check the API docs for Zend_Db_Table_Row_Abstract - the Zend_Db_Table_Select should be passed in as the third parameter, not the second.

Resources