Loading Database tables into jQuery Datatable

I have this code from a script I am porting to Yii:

<table class="datatable">



<th width="100">Photo</th>

<th>First Name</th>

<th>Last Name</th>


<th>Phone Number</th>

<th>Email Address</th>








$result = mysql_query( "SELECT * FROM `bgc_models`" ) or trigger_error( mysql_error() ); 

$num_rows = mysql_num_rows( $result );


if ( $num_rows > 0 ) {

while ( $row = mysql_fetch_array( $result ) ) {

foreach( $row AS $key => $value ) { $row[ $key ] = stripslashes( $value ); }


$state = $row[ 'state' ];


echo "<tr class=\"gradeA\">\n";

echo "<td><a href=\"\" onmouseover=\"dimg('" . $row[ 'main_photo' ] . "');\" onmouseout=\"hideddrivetip()\">View Photo</a></td>\n";

echo "<td>" . $row[ 'first_name' ] . "</td>\n";

echo "<td>" . $row[ 'last_name' ] . "</td>\n";

echo "<td>" . countModelsEmail($row[ 'email' ]) . "</td>\n";

echo "<td><a title=\"Click 2 Call\" href=\"skype:+1" . formatSkype($row[ 'phone_number' ]) . "?call\">" . formatPhoneNumber($row[ 'phone_number' ]) . "</a></td>\n";

echo "<td><a title=\"Click 2 Email\" href=\"mailto:" . $row[ 'email' ] . "\">" . $row[ 'email' ] . "</a></td>\n";

echo "<td>" . getRegion($state) . "</td>\n";

echo "<td>";

if ($row[ 'tags' ] == "" ) {echo "No Tags";} else {echo $row[ 'tags' ];}

echo "</td>\n";

echo "<td class=\"c\"><a title=\"Respond\" href=\"view_model.php?id={$row[ 'id' ]}\"><img src=\"assets/img/respond.png\" /></a>&nbsp;&nbsp;&nbsp;<a title=\"View Model\" href=\"view_model.php?id={$row[ 'id' ]}\"><img src=\"assets/img/view.png\" /></a>&nbsp;&nbsp;&nbsp;<a class=\"confirmLink\" title=\"Delete Model\" href=\"delete_model.php?id={$row[ 'id' ]}&where=mm\"><img src=\"assets/img/delete.png\" /></a></td>\n";

echo "</tr>\n";


echo "</tbody>\n</table>\n";

} else {

echo "There are no entries to return.<br /><br />\n</table>\n";





I have already created all the models for each table in the database but I have never used models in Yii yet and can’t figure this out.

you can put the main table in the view and create a partial view to render each row in the loop. from the controller yuo query your models to retrieve the data and pass the results to the render function.

Thats the thing I don’t get. How to I do a query in a while loop like I did in my original code? I have Googled the hell out of this and found nothing.