I'm working on a code and need to make an association, where I have to count the amount of voting in a video. The problem is that there are 2 tables of videos and votes . In videos
is the videos, and there is the id of the video and the link. In votacoes
has the id_video and who voted. I'm using CodeIgniter to query and list the videos:
Controller:
class Promocao extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('miss_model', 'miss');
}
public function votacao($id = NULL) {
/* Pega os vídeos */
$data['videos'] = $this->miss->find_all('id', 'desc');
$data['titulo'] = 'Votação - TOP CLASS VIP';
$this->load->view('votacao', $data);
}
}
View:
<?php if (count($videos)):foreach ($videos as $row):?>
<div class="col-md-4">
<video width="240" height="240" controls>
<source src="<?php echo base_url('assets/videos/miss/' . $row['video'])?>" type="video/mp4">
<source src="<?php echo base_url('assets/videos/miss/' . $row['video'])?>" type="video/ogg">
Your browser does not support the video tag.
</video>
<?php echo anchor('promocao/votacao/' . $row['id'], 'VOTAR', 'class="btn btn-success"');?>
</div>
<?php endforeach;?>
<?php else:?>
<h1 class="text-center">SEM VÍDEOS</h1>
<?php endif;?>
In view I need to put 30 votes for example, ie display the number of votes cast for each video. The problem is that I do not know how to relate the two tables to the id of the video and id_video of the other table.