0

Hello there im learning php also javascript but i dont know how to put a while loop into javascript parameters area.

<script type="text/javascript" src="//....." async="true"></script>
                <script type="text/javascript">
                window.criteo_q = window.criteo_q || [];
                var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";
                window.criteo_q.push(
                 { event: "setAccount", account: 62056}, // You should never update this line
                 { event: "setEmail", email: "##Email Address of user##" }, // Can be an empty string 
                 { event: "setSiteType", type: deviceType},
                 { event: "viewItem", item: "##HERE##" });
                </script> 

And the goal is output of "##HERE##" needs to be done php while loop from database. (I can give detailed description if asked)

Alper Aslan
  • 47
  • 1
  • 6
  • This will work, somewhat, with a `foreach` loop. However, instead of doing that, I'd recommend just doing `json_encode()` on your items to prevent a formatting headache. – aynber Jul 16 '19 at 17:51
  • Use the `while` loop to create a PHP variable that contains an array of all the items. Then use `item: ` – Barmar Jul 16 '19 at 17:54
  • that solved my problem thank you guyz ;) – Alper Aslan Jul 17 '19 at 17:46

1 Answers1

1

If the file is .php exentension, you could have a <?php echo "JAVASCRIPT CODE" ?> with that you can could an output javascript inputing variables into it, by using concatenating. It is not a good pratice, but would soulve your problem.