I want to make a table of comparison of goods on php for this go I want to write down the ID for which he clicked and compare them then so the problem is that the cycle in the script processes all the IDs. Or just help first

<? $stmt = $pdo->query('SELECT DISTINCT id FROM users'); $i = 0; while ($row = $stmt->fetch()) if(++$i >1) break; { ?> <script> $(document).ready(function() { $( "button" ).click(function() { $( "#basket" ).show( "slow" ); var ID = '<?php echo $row['id']; ?>'; $.ajax({ url: "myscript.php", data: {id: ID}, type: "POST", }) .done(function( data ) {}); }); }); </script> <? } ?> 
how to do if clicked on val 180 then val 180 since three different ads will be compared

    1 answer 1

     <script> $(window).load(function(){ //говорим скрипту что он сработает когда вся страница загрузится $('.btn.btn-primary.btn-lg.width').click(function(e) { //ловим клик $( "#basket" ).show( "slow" ); // показываем как откроется форма var ID = $(this).data('id'); // берет элемент по которому кликнули $.ajax({ // сам ajax запрос url: "myscript.php", // обработчик на php data: {id: ID}, // даные которые передатся type: "POST", // метод }) .done(function( data ) { //отладочный запрос по которому заносятся данные console.log(data); // выводим отладочную информацию }); }); }) </script> 

     и тут заменить , кстати js код снизу под php <button data-id=".$myrow['id']." id='basket-block' val=".$myrow['id']." class='btn btn-primary btn-lg width'> <span class='glyphicon glyphicon-user'> </span> <span class='glyphicon glyphicon-user'> </span>Сравнить </button> 

    • Tell me, is this the answer or the continuation of the question? - Nicolas Chabanovsky
    • yes, the answer. And so now I think to remake it - Koly