php loop in js

Solutions on MaxInterview for php loop in js by the best coders in the world

showing results for - "php loop in js"
Caleigh
07 Apr 2019
1<?php
2$s=array('a','b','c','d','e','f');
3$s_to_json=json_encode((array)$s);
4?>
5
6<script type="text/javascript">
7
8var fromPHP=<? echo $s_to_json ?>;
9
10for (i=0; i<fromPHP.length; i++) {
11
12yourValue=fromPHP[i];
13
14}
15
16</script>
Tom
25 Oct 2019
1<script>
2                                    
3                                    <?php
4                                        $eq = "SELECT * FROM events ORDER BY event_id desc";
5
6                                        //store the result of the query in a variable called $result
7                                        $resulteq=mysqli_query($connection, $eq);
8                                        while($events=mysqli_fetch_assoc($resulteq)) { 
9                                            
10                                            $event_title = $events['event_title'];
11                                            $start_time = $events['event_start_time'];
12                                            $f_start_time = date_create($start_time);
13                                            $event_start_time = date_format($f_start_time, 'c');?>
14
15                                            calendar.addEvent({
16                                                title: '<?=$event_title?>',
17                                                start: '<?=$event_start_time?>',
18                                                url: '../../../main/home.php',
19                                            })
20                                    <?php }?>
21                                    
22                                    calendar.render();
23                                });
24                            </script>