I generate buttons for each element of my database and each button contains a currentSlide() Function which i need to define the slider i want it to open predefined. I am using an array $buttonnums and define each element as "-1" but i want to define it later to another number and apply the change to the html in the same way we say class = " < ?php $var ? >" and afterwards we set the $var to something.
while($row = $result->fetch_assoc()) {
array_push($buttonnums,"-1");
end($buttonnums);
echo "<button class="tablinks" onclick="OpenCoffeeType(event,". $row["id"]."); currentSlide(<?php echo $buttonnums[".key($buttonnums)."]?>)"";
if($count===0)
{
echo " id="defaultOpen"";
$count++;
}
echo ">". $row["title"]. " </button>";
}
and afterwards i set their values here:
while($row2 = $result2->fetch_assoc()) {
if ($count===0)
{
$buttonnums[$count2] = $counter;
}
echo "<span class="dot periexomenakatigorias" onclick="currentSlide(".$counter.")">".$row2["title"]."</span>";
$counter++;
}
The result I get is currentSlide(<php echo $buttonnums[0]?>) instead of getting each time the value of $buttonnums[0]. I upload a picture too here to make it more clear.
question from:
https://stackoverflow.com/questions/65517042/php-echo-html-tags-that-contain-a-variable-to-be-defined-later 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…