I need to find name and address columns only from database
I am usinf the following query
$criteria=new CDbCriteria;
$criteria->select='name';
$criteria->select='address';
$criteria->condition="username=:username";
$criteria->addCondition("active=:active");
$criteria->params=array(':username'=>$this->username,':active'=>1);
$record=User::model()->find($criteria);
But I am geting only 'address'in the output. How can I get both column results? Is there anything similar like addCondition() for specifying wanted columns only for select also ?
Separate your select requirements with commas instead of placing them separately.
$criteria=new CDbCriteria;
$criteria->select='name,address';
$criteria->condition="username=:username";
$criteria->addCondition("active=:active");
$criteria->params=array(':username'=>$this->username,':active'=>1);
$record=User::model()->find($criteria);
Related
How can I select data from two columns using Query\Builder with 'LIKE' %something% and 'OR'.
I get no data if there is no match in column title despite the use of the OR, but there must be a match inside the column subtitle.
I'm currently doing this:
$Query->andWhere(
'MyData.title LIKE :searchValue: OR MyData.subtitle LIKE :searchValue:', [
'searchValue' => '%' . $searchValue . '%',
]
);
Well it looks fine. Are you sure there is match? Maybe check what query is produced? You can easily add logs of all queries using 'db:beforeQuery' event.
Maybe you have some other conditions?
What would the custom expression be to sum data by a category, for each site.
Using the data below, I would like to Sum[X] for only values with category blue, for each site
What I have so far is Sum([X]) OVER [Site] --> Where / how do I put in the category qualifier?
the Intersect() function is a perfect fit here. it creates a hierarchy based on however many columns you list. more info in the documentation.
anyway, try the following:
Sum([X]) OVER (Intersect([Site], [Category]))
To do the same for only a single category, you can use an expression like
Sum(If([Category]="Blue",[X],0)) OVER ([Site])
This will leave a null/empty value when [X] is not "Blue" (case sensitive so beware!).
If you have multiple values, you can replace the condition with
If([X] in ("Blue", "Nurple", "Taupe"), ...)
what I found works best is: Sum(If([Category]="Blue",[X],0)) OVER ([Site])
I am trying to query a database to obtain rows that matches 4 conditions.
The code I'm using is the following:
$result = db_query("SELECT * FROM transportesgeneral WHERE CiudadOrigen LIKE '$origen%' AND DepartamentoOrigen LIKE '$origendep' AND DepartamentoDestino LIKE '$destinodep' AND CiudadDestino LIKE '$destino%'");
But it is not working; Nevertheless, when I try it using only 3 conditions; ie:
$result = db_query("SELECT * FROM transportesgeneral WHERE CiudadOrigen LIKE '$origen%' AND DepartamentoOrigen LIKE '$origendep' AND DepartamentoDestino LIKE '$destinodep'");
It does work. Any idea what I'm doing wrong? Or is it not possible at all?
Thank you so much for your clarification smozgur.
Apparently this was the problem:
I was trying to query the database by using the word that contained a tittle "Petén" so I changed the database info and replaced that word to the same one without the tittle "Peten" and it worked.
Now, im not sure why it does not accept the tittle but that was the problem.
If you have any ideas on how I can use the tittle, I would appreciate that very much.
I would like to filter a parameter based on other values. So the situation is. I want to show only neighborhoods belonging to a certain city, and only if they have games happening certain days.
I'm hoping i do something like the following, this is a bit of a mix of powershell and sql because I don't really know sql as well as I'd like.
foreach ($N in db.Neighborhoods) {
if (db.city = "denver"){
if (db.eventdate in {?start_date} to {?end_date}){
{?Neighborhood} =+ $N
}
}
}
You need to use Record Selection Formula
in that write like below.
datedatabasefield > {?Start Date} and
datedataabsefield < {?End Date}
Along with this your can add other filtering criteria aswell
How can I use "Expression.Not" with text field?
I need to select all records from NHQuestionCount except "ktest"
for example this code return runtime error
NHQuestionCount[] stats = NHQuestionCount.FindAll(Order.Asc("NameFull"), Expression.Not(Expression.Eq("NameFull", "ktest")));
I can't comment on the rest of your code, but your use of Expression is exactly right.