On the site added Polls from VK. The poll code itself was stuffed into MySQL.

Added two polls, and they "got out" on each other.

The two MySQL have the same code:

<!-- Put this script tag to the <head> of your page --> <script type="text/javascript" src="//vk.com/js/api/openapi.js?137"></script> <!-- Put this div tag to the place, where the Poll block will be --> <div id="vk_poll"></div> <script type="text/javascript"> VK.Widgets.Poll("vk_poll", {width: 300, height: 150}, "252365263_929139d2b1c4c5748c"); </script><br> 

 while ($myrow3 = mysqli_fetch_array($result3)){ echo " <div class='news'> ".$content." <p> <table class='info'> <td><img src='img/clock.png'></td> <td>".$date."</td> </table> </p> </div> <hr bgcolor='gray' width='100%'>"; } 

In connection to the database everything is OK:

Screenshot display of polls

  • Those. Do you have two identical widgets inserted into divs with the same id? - br3t

1 answer 1

Actually, the problem is that you initialize the widgets into the same block.

Through the loop, you create two blocks with the same ID:

 <div id="vk_poll"></div> <div id="vk_poll"></div> 

When executing this code, you put everything into a block with the ID of vk_poll (the first parameter):

 VK.Widgets.Poll("vk_poll", {width: 300, height: 150}, "252365263_929139d2b1c4c5748c"); 

But the fact is that, according to the HTML specification, there should not be two elements with the same id attributes on the page, due to which both widgets are crookedly initialized to the first <div> .

The obvious solution to the problem is to change the code like this:

 <div id="vk_poll1"></div> <script type="text/javascript"> VK.Widgets.Poll("vk_poll1", {width: 300, height: 150}, "252365263_929139d2b1c4c5748c"); </script> <div id="vk_poll2"></div> <script type="text/javascript"> VK.Widgets.Poll("vk_poll2", {width: 300, height: 150}, "252365263_929139d2b1c4c5748c"); </script> 

I also advise you to review the implementation of your application, because at a minimum, storing JavaScript and HTML in the database is often a bad idea. Ideally, you should store in the database only the poll ID, namely this part: 252365263_929139d2b1c4c5748c .

And you don’t need <script type="text/javascript" src="//vk.com/js/api/openapi.js?137"></script> to be inserted into the page twice.