Question

I'm in trouble with a simple php foreach wich attribute classes (odd / even) to divs. I think i have a synthax error because it works but the loop is not ended (Uncaught RangeError: Maximum call stack size exceeded in console :

<?php
$count = 0;

foreach( $this->boutiques_details as $key => $value){
     if ($value->ville == $this->ville)     {

echo '<div data-lng="$this->escape($value->longitude)" data-lat=" $this->escape($value->latitude)" class="' . (++$count%2 ? "shop odd" : "shop even") . '">';
?>
        <p><b><?php echo $this->escape($value->ville)?></b></p>
        <p><?php echo $this->escape($value->quartier)?></p>
        <p><?php echo $this->escape($value->adresse)?></p>
        <p><?php echo $this->escape($value->num_contact_1)?></p>
        </div>
  <?php
        }
 }

?>

Thanks for help!

Was it helpful?

Solution

You have some PHP code in the string you're trying to echo, but it's not being evaluated by PHP because it's inside the string:

echo '<div data-lng="$this->escape($value->longitude)" data-lat="$this->escape($value->latitude)" class="' . (++$count%2 ? "shop odd" : "shop even") . '">';

Replace the above with the following:

echo '<div data-lng="' . $this->escape($value->longitude) . '" data-lat="' . $this->escape($value->latitude) . '" class="' . (++$count%2 ? "shop odd" : "shop even") . '">';

This way, the PHP parts (such as $this->escape($value->longitude)) will be recognized by PHP, and their results will be inserted in the string you are echoing.

Because you were echoing the PHP parts directly, javascript (jQuery) probably recognized the dollar sign ($), tried to do something with it but didn't know how, and failed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top