This code returns all of the right information. However, I wanted to exclude whichever product the user is currently looking at.
i.e.
If the user is looking at product 1 for the creator "admin"
it will show all other products from creator "admin" except for the current one they are looking at (product 1).
I guess how do you add a condition to exclude this?
$assetArray = Addon::model()->findAllByAttributes(array("creator"=>$model->creator0->id));
Thank you!
4123
Try:
$assetArray = Addon::model()->findAllByAttributes(
array("creator"=>$model->creator0->id),
array('condition'=>'addon_id != :currentID'),
array(':currentID'=>$current_id)
);
thanks for the reply however, that didn’t work. It threw undefined var $current_id.
So I added the var (just said $current_id = ‘1’ to test it) and then it threw
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens.
here is the actual sql statement error log
CDbCommand::fetchAll() failed: SQLSTATE[HY093]: Invalid parameter number:
number of bound variables does not match number of tokens. The SQL
statement executed was: SELECT * FROM addon
t
WHERE t
.creator
=:yp0
AND (id != :1).
Any other ideas?
lalzada
(Lalzadamohmand)
4
try this…its working here…
$criteria = new CDbCriteria();
$criteria->condition = 'creator_id =:creator_id AND currentID !=:currentID';
$criteria->params = array(':creator_id'=>$model->creator0->id, ':currentID'=>$current_id);
$assetArray = Addon::model()->findAllByAttributes(array() , $criteria);
Thanks for this! I got it to work with a couple of changes! Here is the whole code.
<?php
$current_id = $model->id;
$criteria = new CDbCriteria();
$criteria->condition = 'creator =:creator AND id !=:id';
$criteria->params = array(':creator'=>$model->creator0->id, ':id'=>$current_id);
$criteria->limit='6';
$assetArray = Addon::model()->findAllByAttributes(array() , $criteria);
$dataProvider = new CArrayDataProvider($assetArray, array('keyField'=>'id'));
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_authorother',
'id'=>'addonListView',
'template'=>'{items}',
'emptyText'=>'',
)); ?>