Shaani
(Aziz Zee)
August 10, 2012, 7:33am
1
$data = Districts::model()->findAllByAttributes(array((int) $_POST['myArea']),'emirateId=:idCity', array(':idCity'=>(int) $_POST['myArea']));
When I select All Cities from the dropDownList the ajax POST is myArea 2,1. The above findAllByAttributes query is giving error Table “districts” does not have a column named “0”. I’m trying to generate IN condition: WHERE emirateID IN (2,1). $_POST[‘myArea’] can have values 1, 2 or 2, 1
I have tried this
$data = Districts::model()->findAll('emirateId IN (:idCity)', array(':idCity'=>(int) $_POST['myArea']));
but this gives empty query result when $_POST[‘myArea’] is 2,1. It works fine when $_POST[‘myArea’] is 1
alirz23
(Alirz23)
August 10, 2012, 8:13am
2
hi you have to construct a array of intgers
$data = Districts::model()->findAllByAttributes(array((int) $_POST['myArea']),'emirateId=:idCity', array(':idCity'=>(int) $_POST['myArea']));
you see this part right here you converting an array to int obviously its gonna give you 0
array((int) $_POST['myArea'])
replace it with
$_POST['myArea']
Shaani
(Aziz Zee)
August 10, 2012, 8:26am
3
alirz23:
hi you have to construct a array of intgers
$data = Districts::model()->findAllByAttributes(array((int) $_POST['myArea']),'emirateId=:idCity', array(':idCity'=>(int) $_POST['myArea']));
you see this part right here you converting an array to int obviously its gonna give you 0
array((int) $_POST['myArea'])
replace it with
$_POST['myArea']
Using $_POST[‘myArea’]
$data = Districts::model()->findAllByAttributes($_POST['myArea'],'emirateId=:idCity', array(':idCity'=>(int) $_POST['myArea']));
$data = CHtml::listData($data,'districtId','districtName');
$dropDownDistricts = "<input type='checkbox' value=''>All Districts<br>";
foreach($data as $value=>$name)
$dropDownDistricts .= CHtml::tag('input', array('name'=>'district', 'type'=>'checkbox', 'value'=>$value),CHtml::encode($name),true).
gives error: Invalid argument supplied for foreach()
Using array($_POST[‘myArea’])
$data = Districts::model()->findAllByAttributes(array($_POST['myArea']),'emirateId=:idCity', array(':idCity'=>(int) $_POST['myArea']));
gives error: Table "districts" does not have a column named "0".
alirz23
(Alirz23)
August 10, 2012, 8:32am
4
hi shaani
do not warp the whole thing in an array type cast to array by using the following
(array) $_POST['Area'];
and please do let me know what is your value for the $_POST[‘Area’];
Shaani
(Aziz Zee)
August 10, 2012, 8:39am
5
getting error: Table “districts” does not have a column named “0” when using (array) $_POST[‘myArea’]
$_POST[‘myArea’] has value 1 for Dubai, 2 for Abu Dhabi and 2,1 for All Cities
$cities= array('2,1'=>'All Cities', '2'=>'Abu dhabi', '1'=>'Dubai');
echo CHtml::dropDownList('myArea','', $cities,
array(
'class'=>"enquiry-select",
'prompt'=>'-Select-',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('site/updateCities'),
'dataType'=>'json',
'data'=>array('myArea'=>'js:this.value'),
'success'=>'function(data) {
$("#district").html(data.dropDownDistricts);
}',
)));
public function actionUpdateCities()
{
//District
$data = Districts::model()->findAllByAttributes((array)$_POST['myArea'],'emirateId=:idCity', array(':idCity'=>(int) $_POST['myArea']));
$data = CHtml::listData($data,'districtId','districtName');
$dropDownDistricts = "<input type='checkbox' value=''>All Districts<br>";
foreach($data as $value=>$name)
$dropDownDistricts .= CHtml::tag('input', array('name'=>'district', 'type'=>'checkbox', 'value'=>$value),CHtml::encode($name),true). "<br>";
// return data (JSON formatted)
echo CJSON::encode(array(
'dropDownDistricts'=>$dropDownDistricts
));
}
alirz23
(Alirz23)
August 10, 2012, 9:03am
6
sorry about all that i did not pay attention
$cities = explode(",", $_POST['myArea']);
$data = Districts::model()->findAllByAttributes( array('emirateId'=> $cities) );
try this should work