Reputation: 23
Hi I'm trying to update my HTML reservation sheet based on a MySQL query. I tried to use a PHP while
loop in my JavaScript but I can't do it.
Here's my code
<script type="text/javascript">
<?php
$date = $_GET['JOUR'];
$login = $_GET['NAME'];
require('bdd.php');
//here my query
$req = "SELECT * FROM RESERVATION WHERE resa_jour = '$date'";
//here I exec the query
$reponse = $bdd->query($req);
while ($data = $reponse->fetch())
{
?>
jQuery(function ($) {
if (<?php echo $data['id'] ?>) {
$('.<?php echo $data['resa_salle'] . $data['resa_periode'] ?>').addClass('disable');
}
});
<?php } ?>
</script>
Upvotes: 0
Views: 482
Reputation: 4674
I think this is the bad idea. You should pass only result in a JS variable and then first saw that in which format that is JSON or ARRAY. Then run a loop in as
$.each(data, function(index, value){
-- your code here --
});
JS and add class in that way.
Upvotes: 1