Passing A Dropdown Value To Varaible/url

Had to delete my previous topic because of the following:

I have several SQL functions in my controller , to which I call from a table in the view.

However , I want to pass a certain value to those functions from a dropdown I have in the view as well (bypassing the post to model/controller like I thought before)


<?php

echo CHtml::dropDownList('wid','$week_id',Event::model()->getWeekOptions2());


echo "<table>";

echo "<tr>";

	echo "<td>".$this->countCon(18)."</td>"; //for exapmle

	echo "<td>".$this->countAllspec()."</td>";

	echo "<td>".$this->countSpec()."</td>";

	echo "<td>".$this->countActCon()."</td>";

	echo "<td>".$this->countSpec2()."</td>";

	echo "<td>".$this->countZero()."</td>";

	echo "<td>".$this->countLink()."</td>";

echo "</tr>";

echo "</table>";


?>

Now , in the first function I put 18 as an example , but instead of it , I want the number to be from the wid dropdownlist I have at the beginning of my code.

How that is possible?

Thanks,

Mark.

Do you want the values in the table to change when the drop down changes?

I think you’re going to have to post to the controller:


<?php

echo CHtml::dropDownList('wid','$week_id',Event::model()->getWeekOptions2(), array(

       'ajax'=>array(

		'type'=>'POST',

		'url'=>CController::createUrl('something/someAction'),

		'dataType'=>'json',

		'success'=>'function(data){

                     $("#conCount").html(data.conCount);

		}',

	)

);


echo "<table>";

echo "<tr>";

	echo "<td><span id="conCount"></span></td>"; //for exapmle

	echo "<td>".$this->countAllspec()."</td>";

	echo "<td>".$this->countSpec()."</td>";

	echo "<td>".$this->countActCon()."</td>";

	echo "<td>".$this->countSpec2()."</td>";

	echo "<td>".$this->countZero()."</td>";

	echo "<td>".$this->countLink()."</td>";

echo "</tr>";

echo "</table>";


?>



Then in your controller:




public function actionSomeAction()

{

   $model = loadYourModel();

   $wid = $_POST['wid'];


   $conCount = $model->countCon($wid);

   echo CJSON::encode(array('conCount'=>$conCount));

   return;

}



Hello compact_corpse.

I’m trying to use your solution , but the <Span> is giving me a white screen. . .

Was it the quotes?




echo "<td><span id="conCount"></span></td>"; // this

echo '<td><span id="conCount"></span></td>'; // to this



Or, if that’s not it, does the ajax request get sent on dropdown change? What’s the response you get from the controller?

Yes , the single quote solved that one.

But now I get the following error when I put $wid in my model’s action:

model:


public function countCon($wid)

	{

		$week=Person_Event::model()->weekByDate();

	$week_id=$week->id;

		$datalogin=mysqli_connect("192.168.1.137", "volapp", "t2ru3s1Lv","vol_app");

		$sql ="SELECT `id` FROM `tbl_event` WHERE `week_id`=$wid"; 

	$query = mysqli_query($datalogin, $sql);

	$numrows = mysqli_num_rows($query);

	return $numrows;

	}

controller:


public function actionWeekset()

{

   $model=Event::model();           //did you mean this by loading my model?

   $wid = $_POST['wid'];


   $conCount = $model->countCon($wid);

   echo CJSON::encode(array('conCount'=>$conCount));

   return;

}

Thanks,

Mark.