Reputation: 61
The value of the for loop is stuck at 1.
I am trying to run this loop to print the name of the event at the top of the modal box. But the same name appears each time.
I've given continue statement and tried too. Yet the value of $i is stuck at 1
It would be of great help if you could find a solution for this
Thanks in advance.
<?php $noofevents = DB::table('events')->count(); ?>
@for($i = 1; $i <= $noofevents; $i++)
<?php $current_event_name = DB::table('events')->where('id',$i)->value('Event_Name'); ?>
<div id="sponsor-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="display-4" style = "text-align : center; font-size : 30px;">Sponsors for {{$current_event_name}}</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-content">
<img src ="{{asset('images/Sponsors/paytm.jpg')}}" alt ="" width = "200px" class = "mx-auto d-block">
</div>
<div class="card-footer">
<p class = "text-center"></p>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@endfor
Upvotes: 0
Views: 115
Reputation: 2453
You need to differentiate modal box with different ids
Please Use this part in your controller and pass it to your blade view using compact.
<?php $noofevents = DB::table('events')->count(); ?>
Use this part in blade :
@for($i = 1; $i <= $noofevents; $i++)
<?php $current_event_name = DB::table('events')->where('id',$i)->value('Event_Name'); ?>
<div id="sponsor-modal{{ $i }}" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="display-4" style = "text-align : center; font-size : 30px;">Sponsors for {{$current_event_name}}</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<div class="card">
<div class="card-content">
<img src ="{{asset('images/Sponsors/paytm.jpg')}}" alt ="" width = "200px" class = "mx-auto d-block">
</div>
<div class="card-footer">
<p class = "text-center"></p>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@endfor
So now you have different modal boxes for total noofevents. you need to call this modal boxes with ids appended by $i.
Upvotes: 1