I'm trying to get the next product ID, but it says that I need to specify criteria... CDbCriteria. I searched around, I don't see other people using criteria so I must be doing something wrong?? I am looking for the next product_id.
public function getNextID()
{
$model = new Product();
$last_ID= $model->findByAttributes(array('product_id'=>'product_id DESC'));
$next_ID=$last_ID+1;
return $next_ID;
}
Do not quite understand what to know before you insert id, but try to do so
$criteria = new CDbCriteria();
$criteria->select = 'id';
$criteria->order = 'id DESC';
$criteria->limit = 1;
$product = Product::model()->find($criteria);
// id of last row
$lastId = $product->id;
Related
I want check if ID reserved in DB, delete it and add new record with this ID.
$model = new TaxRulesGroup(2);
$model->delete();
$model->id = 2;
$model->id_tax_rules_group = 2;
$model->name = 'new name';
$model->active = 1;
$model->add();
any ideas ? Thank you.
From the ObjectModel class has attribute "force_id". I love PrestaShop. ;)
/** #var bool Enables to define an ID before adding object. */
public $force_id = false;
I need to use where clause on yii, below of my code, I need to add where activated == 0 && send_email == 0.
$model = User::model()->findAll();
Thanks
There are multiple ways to do this:
$model = User::model()->findAll('activated=0 AND send_email=0');
Or,
$model = User::model()->findAll('activated=:activated And send_email=:sendEmail',
array(':activated'=>0,':sendEmail'=> 0));
Or,
$criteria = new CDbCriteria;
$criteria->condition='activated=:activated AND send_email=:sendEmail';
$criteria->params=array(':activated'=>0,':sendEmail'=>0);
$model=User::model()->findAll($criteria);
Or,
$model = User::model()->findAllByAttributes(array('activated'=>0, 'send_email'=>0));
Or,
$model = User::model()->findAllBySql('SELECT * FROM user WHERE activated=:activated AND send_email=:sendEmail', array(':activated'=>0, 'sendEmail'=>0));
More info here. Hope that helps :)
Simply try this:
$model = User::model()->findAll(array("condition"=> "activated=0 AND send_email=0"));
SELECT Name, ProfileId, Id, Username FROM User this is the select query to retrive data in Force.com explorer
Now I wan't to update a column how can I do this? update key word it self not working here please give the solution for this.
thanks in advance
In Salesforce you not write to update query same as in SQL.
Please use update method to update column of an object.
More information and sample please read following documents.
https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_update.htm
I found Solution it's working fine now, If any one haveing doubts ask me for Create,Update,Get functionalities
private void UpdateProfileId(string Id)
{
SforceService sfs = new SforceService();
var login = sfs.login(ConfigurationManager.AppSettings["username"],ConfigurationManager.AppSettings["password"]);
sfs.Url = login.serverUrl;
sfs.SessionHeaderValue = new SessionHeader();
sfs.SessionHeaderValue.sessionId = login.sessionId;
var userinfo = login.userInfo;
QueryResult qr = null;
sfs.QueryOptionsValue = new salesforce.QueryOptions();
User[] UpdateUser = new User[1];
User objuser = new User();
objuser.Id = Id;
objuser.ProfileId = "00e90000001CcTnAAK";
UpdateUser[0] = objuser;
try
{
SaveResult[] saveResults = sfs.update(UpdateUser);
foreach (SaveResult saveResult in saveResults)
{
if (saveResult.success)
{
Console.WriteLine("Successfully updated Account ID: " +saveResult.id);
}
}
}
}
I've got this code working but it's only pulling out the first neighbourhood group that matches one of the values from the 1st query. The code is in a Node ID PHP handler in a view in Drupal.
The first query puts all of the postal codes from the government's jurisdiction into an array. The second query reads through all of the neighbourhood groups to find all those that match those in that array.
It looks like I need a second loop or something since the while that's there now isn't getting every neighbourhood groups that match any of the values in the array. Can anyone see what I'm missing?
Here's the code:
$government_nid = custom_get_groupid();
$codes_list = array();
$neighbourhood_list = array();
$results = db_query("SELECT field_jurisdiction_postal_codes_value FROM {content_field_jurisdiction_postal_codes} WHERE
nid = %d", $government_nid);
while($return_list = db_fetch_array($results)){
$codes_list[] = $return_list[field_jurisdiction_postal_codes_value];
}
$results1 = db_query("SELECT nid FROM {content_type_neighbourhood_group} WHERE
field_postal_code_3_value IN ('%s')", $codes_list);
while($return_list1 = db_fetch_array($results1)){
$neighbourhood_list[] = $return_list1[nid];
}
$neighbourhood_string = implode(', ', $neighbourhood_list);
return $neighbourhood_string;
Here's the answer:
foreach ($codes_list AS $value) {
$results1 = db_query("SELECT nid FROM {content_type_neighbourhood_group} WHERE
field_postal_code_3_value = '%s'", $value);
while($return_list1 = db_fetch_array($results1)){
$neighbourhood_list[] = $return_list1[nid];
}
}
$neighbourhood_string = implode(', ', $neighbourhood_list);
return $neighbourhood_string;
let' say i have 20 results in the sql query. if am gonna use the limit in the yii active record, I'll obviously get the first four from the result, but what if i wanna get the 2nd four and then 3rd four in the same query result ? how to query that via sql ?
e.g
$criteria2 = new CDbCriteria();
$criteria2->select = 'USERID, ADID ,ADTYPE, ADTITLE, ADDESC, PAGEVIEW, DISPPUBLISHDATE';
$criteria2->addCondition("STATUS = 1");
$criteria2->order = '"t".PAGEVIEW DESC,"t".PUBLISHDATE DESC';
$criteria2->limit = 4;
$criteria2->with = array('subcat','adimages');
$result = $this->findAll($criteria2);
return $result;
Sorry :)
See here, how to paginate with Oracle (Are you use 11g?)
Alternatives to LIMIT and OFFSET for paging in Oracle
Well and in Yii just set offset, OCIConnector will set rownum automaticly for sql
$criteria2 = new CDbCriteria();
$criteria2->select = 'USERID, ADID ,ADTYPE, ADTITLE, ADDESC, PAGEVIEW, DISPPUBLISHDATE';
$criteria2->addCondition("STATUS = 1");
$criteria2->order = '"t".PAGEVIEW DESC,"t".PUBLISHDATE DESC';
$criteria2->limit = 4;
$criteria2->offset = 0; //4, 8 - COciCommandBuiled applyLimit use it
$criteria2->with = array('subcat','adimages');
$result = $this->findAll($criteria2);
return $result;