[eluser]sandwormusmc[/eluser]
Sure.
1. Create a function in your main controller called setAction (for below).
2. Point your AJAX to your main controller.
3. Create the model function to do the count of the table.
HTML:
Code:
<a href="#" onClick='doAjax(countMyTable);'>Click me for AJAX goodness</a>
<div id='countMyTable'> </div>
JavaScript to include in your HTML:
Code:
var baseURL='<?=base_url()?>index.php/<REPLACE WITH MainControllerName>';
function doAjax(target) {
var url = baseURL+'/setAction/'+target;
var ajax = new Ajax(url, {
method: 'get',
update: $(target)
}).request();
}
PHP in your main controller:
Code:
public function setAction(){
$tableName=$this->CI->uri->segment(3);
$this->CI->load->model('count_model','',TRUE);
$result=$this->CI->count_model->countMeh($tableName);
print_r($result);
}
PHP in count_model:
Code:
<?
class count_model extends Model {
public function __construct(){
parent::Model();
}
public function countMeh($tableName){
$sql="SELECT COUNT(*) FROM `$tableName`;";
$result=$this->db->query($sql);
$count=$result->row();
return $count;
}
}
That should do it ... change the print_r in the main controller to make the output more readable.
Does that work?