Hello. I am wondering how to display a variable that is calculated for each foreach instance in php

Development is conducted on laravel. By this, the syntax is blade and helpers from laravel.

Sample code.

{{ $items = App\Items::all() }} @foreach($items as $item) <span>{{$item->title}}</span> <span>{{$item->content}}</span> <span id="price></span> @endforeach <script> var minPrice = parseInt("{{ $item->start_price }}"); var maxPrice = parseInt("{{ $item->final_price }}"); var price = minPrice; var delta = (maxPrice - minPrice) / 86400; //разница между начальной и конечной ценой разделенной на 24 часа в секундах function setPrice() { document.getElementById("price").innerHTML = price; price += delta; if (price > maxPrice) price = minPrice; price = Math.round(price * 100) / 100; } setPrice(); setInterval(setPrice, 1000); 

How to display price variable for each $ items instance

Thank you in advance !

  • Obviously you need to add code using $ item inside foreach - Grundy
  • Thanks for the fast reply. And in the example, what will it look like? - MeKree
  • also you take your code and transfer it - Grundy
  • JS can only display one id, so the transfer will not help here because the same id will be repeated several times, and only the first one found will work - MeKree
  • Then open the question: what exactly do you want to display, if you yourself say - that you only draw in one element :-) - Grundy

0