Query With An Array Of Data

Hello all,

Please am having a little challenge. What i want to do is simple but i cant get it done.

I have a multiple select box the post array of values to my controller.

lets say:

$data = array(1,2,3,4,5)

in my controller, what i would like to do is to run yii createCommand where coloumn_name = $data. but my function actionSendRfp($id) returns one record. instead of 5 records.

Can anybody help me?

public function actionSendRfp($id)

    {


        $data = $this->loadModel($id);


        $model = new Rfpmessagelog;


        $v = new Vendors;


         


        if(isset($_POST['Rfpmessagelog']))


        {


            $model->attributes = $_POST['Rfpmessagelog'];


            $model->vendors_name = $_POST['vendors_name_selected'];


            $model->validate();


            $split  = explode(",",$model->vendors_name); // this is an array of data ("1,2,3,4,5")


            foreach($split as $key=>$vendors)


            {   


                


                $result = Yii::app()->db->createCommand()


                ->select('*')->from('tbl_vendors')


                ->where('company_name=:company_name', array(':company_name'=>$vendors))


                ->queryRow();


                //$findVendors = Vendors::model()->find('company_name =:company_name',array(':company_name'=>$vendors));


                echo $result['email']."</br>";


            }

try this




$required_data=array();

foreach($split as $key=>$vendors)

{


$result = Yii::app()->db->createCommand()

->select('*')->from('tbl_vendors')

->where('company_name=:company_name', array(':company_name'=>$vendors))

->queryRow();

//$findVendors = Vendors::model()->find('company_name =:company_name',array(':company_name'=>$vendors));

$required_data[$key]= $result['email']."</br>";

} 

// now use $required_data



Thanks but am getting error.

Invalid argument supplied for foreach()

Oh sorry, no error, but if i echo $required_data[$key], it returns only one email address. what i want to do is to send email to all the email addresses after retrieving them

$required_data=array();

            foreach(&#036;split as &#036;key=&gt;&#036;vendors)


            {





            &#036;result = Yii::app()-&gt;db-&gt;createCommand()


            -&gt;select('*')-&gt;from('tbl_vendors')


            -&gt;where('company_name=:company_name', array(':company_name'=&gt;&#036;vendors))


            -&gt;queryRow();


            //&#036;findVendors = Vendors::model()-&gt;find('company_name =:company_name',array(':company_name'=&gt;&#036;vendors));


            &#036;required_data[&#036;key]= &#036;result['email'].&quot;&lt;/br&gt;&quot;;


            


            }


            echo &#036;required_data[1];

Please can anybody help me? I’m stucked right now if i echo var_dump($required_data); this is the array returned. The query can only find the first record

array(4) { [0]=> string(34) "xxx@xxx.com

" [1]=> string(5) "

" [2]=> string(5) "

" [3]=> string(5) "

" }

first check what is output of




$model->vendors_name



then check output




print_r($split)



thanks

$model->vendors_name returns

company A, company B, company C, company D

print_r($split) returns Array.

var dump($split) returns

array(4) { [0]=> string(7) "Company A" [1]=> string(29) "Company B" [2]=> string(5) "Company C" [3]=> string(5) "Company D" }

Thanks. what should i do?

[color="#006400"]/* moved from Feature Requests */[/color]

Thanks, i got it solved. The problem came from $_POST[‘vendors_name_selected’];. it contained some empty space which i had to trim.

hmm Good