Answers for "js loop php"

PHP
1

javascript php loop

<?php
$s=array('a','b','c','d','e','f');
$s_to_json=json_encode((array)$s);
?>

<script type="text/javascript">

var fromPHP=<? echo $s_to_json ?>;

for (i=0; i<fromPHP.length; i++) {

yourValue=fromPHP[i];

}

</script>
Posted by: Guest on July-27-2020
0

php loop in js

<script>
                                    
                                    <?php
                                        $eq = "SELECT * FROM events ORDER BY event_id desc";

                                        //store the result of the query in a variable called $result
                                        $resulteq=mysqli_query($connection, $eq);
                                        while($events=mysqli_fetch_assoc($resulteq)) { 
                                            
                                            $event_title = $events['event_title'];
                                            $start_time = $events['event_start_time'];
                                            $f_start_time = date_create($start_time);
                                            $event_start_time = date_format($f_start_time, 'c');?>

                                            calendar.addEvent({
                                                title: '<?=$event_title?>',
                                                start: '<?=$event_start_time?>',
                                                url: '../../../main/home.php',
                                            })
                                    <?php }?>
                                    
                                    calendar.render();
                                });
                            </script>
Posted by: Guest on September-07-2021

Browse Popular Code Answers by Language