SELECT `t1`.`id`, `t1`.`name`, COUNT(`t2`.`id`) AS cnt
FROM `table` as `t1`
LEFT JOIN `table` `t2` ON `t1`.`id` = `t2`.`ref_id`
WHERE (`t1`.`param1` + `t1`.`param2` + `t1`.`param3`) > 5
GROUP BY `t1`.`id`
ORDER BY cnt DESC
SELECT `t1`.`id`, `t1`.`name`, COUNT(`t2`.`id`) AS cnt
FROM `table` as `t1`
LEFT JOIN `table` `t2` ON `t1`.`id` = `t2`.`ref_id`
AND (`t2`.`param1` + `t2`.`param2` + `t2`.`param3`) > 5
WHERE (`t1`.`param1` + `t1`.`param2` + `t1`.`param3`) > 5
GROUP BY `t1`.`id` ORDER BY cnt DESC
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(function(){
$('#button').click(function(){
$.ajax({
type: "POST",
url: '/your-file.php',
success: function(data) {
alert("Выполнился");
$('#result').html(data);
}
});
});
});
</script>
<div id = "button"> Нажми меня </div>
<div id = "result"> Результат </div>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
$(function(){
$(location.hash).click();
$(window).hashchange(function(){
$(location.hash).click();
});
});
$users = Users::model()->findAll();
$user = Users::model()->findByPk($id);
class Users extends CActiveRecord
{
…
public function relations()
{
return array(
'messages'=>array(self::HAS_MANY, 'Messages', 'user_id')
);
}
}
$user->messages