-6
I am developing a website to display registered videos, for this I did with a select to select the desired discipline of the user. Soon after I put a button to display these registered videos pulling from MYSQL (based on the selected discipline).
How can I get the id of select and search, based on this id of the selected discipline, the uploaded videos?
I have a part of a previous code, but it was used to identify the logged in user, can serve as a basis for solving the problem.
Search code in mysql:
<?php
$disciplina = $_SESSION['disciplina_prof'];
$servidor = 'localhost';
$usuario = 'root';
$senha = 'root';
$banco = 'onteach';
$conexao = mysqli_connect($servidor, $usuario, $senha, $banco);
$consulta = "SELECT
*
FROM
video_monitor
WHERE
video_monitor.disciplina = '$disciplina'
AND video_monitor.pendente = 1";
$resultados = mysqli_query($conexao, $consulta);
$videos_pendentes = array();
while ($video = mysqli_fetch_assoc($resultados))
$videos_pendentes[] = $video;
mysqli_free_result($resultados);
mysqli_close($conexao);
$videos_pendentes = json_encode($videos_pendentes);
?>
Script code to select the data that will appear in the Carousel: (modify to the DISCIPLINE ID, 1 for "Physics", 2 for "Mathematics") The select of this discipline is in html like this:
<div class="box">
<select name="disciplina_prof" id="disciplina_prof">
<option value="" selected=selected>Selecione uma disciplina</option>
<?php
if($num_logar > 0) {
do {
echo "<option value='".$fet_logar['disciplina_id']."'>".$fet_logar['disciplina_nome']."</option>";
}while($fet_logar = mysqli_fetch_assoc($exe_logar));
}
?>
</select>
<?php print_r($consulta);?>
</div>
An example that after mysql selected the discipline these would be displayed in Carousel:
$('#btn-lista-videos-carousel').click(function() {
let itens = '';
let indicadores = '';
if (videos_pendentes.length > 0) {
videos_pendentes.forEach(function(video, indice) {
indicadores += '<li data-target="#carouselExampleIndicators" data-slide-to="' + indice + '" class="' + (indice == 0? 'active' : '') + '"></li>'
itens += '<div class="carousel-item ' + (indice == 0? 'active' : '') + '">';
itens += ' <iframe width="100%" height="350" src="https://www.youtube.com/embed/'+ video.link_video +'" frameborder="0" allowfullscreen></iframe>'
itens += '</div>';
});
console.log(indicadores);
$('#carouselExampleIndicators').show();
$('#carousel-indicadores').html( indicadores );
$('#carousel-itens').html( itens );
} else {
alert('Nenhum vídeo pendente');
}
});
$('.carousel').carousel();
});
</script>
Probably the table should have a field
id
, just call this field in the query as well– MagicHat
You need to improve the way you are exposing the problem... To do this dynamically you need Ajax, but first you must take the
id
... So what’s the problem in question, getting theid
or do or Ajax?– MagicHat
You cannot keep changing the question except to improve details, when you invalidate answers given the question was bad and the solution is not to do another.
– Maniero
That’s why you have to work on the posts, the system punishes repeated bad questions. There was a sign from you that the answer was no longer valid for the question and it doesn’t seem to be the same question.
– Maniero
@Matheus You need to make an Ajax call based on select, there are several examples on the site gives a search
– MagicHat
@Matheus does not skip steps, otherwise you will be trapped in a loop of copying and pasting codes that will never consciously take you to your destination. Stop your code a bit and understand the foundation of how Ajax technology works so you can implement it in your code.
– MagicHat
Matheus@ and then brother already managed to solve the problem ?
– MichaelCosta
@Michaelcosta not yet :(
– Matheus
@Matheus, at this moment, what is the problem ? ta giving error ?
– MichaelCosta
As far as I understand it, you want the person to select which discipline they want to see, after that, you want a button to send the chosen discipline of select to store in your Sesssion['disciplina_prof']; that’s it ?
– MichaelCosta
That would be right @Michaelcosta
– Matheus
But I will edit to put the discipline select for you
– Matheus
Let’s go continue this discussion in chat.
– Matheus