Help With Sql Output For Each Loop In A _Form.php


After an earlier post to get some guidance on the direction to take, any help with the following would be most appreciated.

I am trying to create a simple form which allows the users to enter the sports results for their players.

In my controller I have 2 SQL queries:

The first returns the players associated with the venue

The second returns a total count of how many players there are at that venue.

This all works and returns the correct data as shown below:


public function actionCreate()


		$type=(Yii::app()->user->user_type); 			// Get the user type


		if(($type==='venue') || ($type=='gd')) {


			$id=(Yii::app()->user->venue_user_id); 		// set the venue ID for use as the 'bindValue'


			// Return all the players associated with the users venue

			$sqlPlayers='SELECT * FROM player LEFT JOIN player_venues ON = player_venues.player_id WHERE player_venues.venue_id=:id AND = "yes"';

			$playerList = Yii::app()->db->createCommand($sqlPlayers)->bindValue('id',$id)->queryAll();

			// Count how many players are associated with the users venue

			$sqlCount='SELECT COUNT(*) FROM player LEFT JOIN player_venues ON = player_venues.player_id WHERE player_venues.venue_id=:id AND = "yes"';

			$playerCount = Yii::app()->db->createCommand($sqlCount)->bindValue('id',$id)->queryScalar();

			// debug

			echo "<pre>";

			print_r ($playerCount);

			echo "</pre>";

			echo "<pre>";

			print_r ($playerList);

			echo "</pre>";			






Test Output




    [0] => Array


            [id] => 1

            [player_salutation] => Mr.

            [player_forename] => Shaun

            [player_surname] => Smith            

            [active] => yes


    [1] => Array


            [id] => 2

            [player_salutation] => Mr.

            [player_forename] => Andrew

            [player_surname] => Clark

            [active] => yes


    [2] => Array


            [id] => 14

            [player_salutation] => Mr.

            [player_forename] => Paul

            [player_surname] => Walters

            [active] => yes


    [3] => Array


            [id] => 15

            [player_salutation] => Mrs.

            [player_forename] => Susan

            [player_surname] => Jones

            [active] => yes



My task is to first display a dropdown asking the user to select how many players took part in the game.

The dropdown will contain a list of values from zero up to the value of $playerCount

This selection will then loop through the required value creating a set of dropdown’s each containing a list of all possible players passed from $playerList

Then all the user needs to do is work down the list selecting each player and their resulting position

My problem is I am unsure how to loop and output into my form using the array and total player count which I have created in the controller?



/* @var $this GameResultsController */

/* @var $model GameResults */

/* @var $form CActiveForm */


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(


	// Please note: When you enable ajax validation, make sure the corresponding

	// controller action is handling ajax validation correctly.

	// There is a call to performAjaxValidation() commented in generated controller code.

	// See class documentation of CActiveForm for details on this.


)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($playerList); ?>


	<div class="row">

		dropdown list here how many players?


	<?php foreach( <img src='' class='bbc_emoticon' alt='???' /> ) ?> 

	<div class="row">

		<?php echo $form->dropDownList($playerList,'id',

	        array('id' => 'player_surname'); 



	<?php endforeach; ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton($playerList->isNewRecord ? 'Create' : 'Save'); ?>


<?php $this->endWidget(); ?>

</div><!-- form -->

Example of the desired view

Once again, many thanks in advance for any help with this problem