There is a script separately. Everything is fine.

WHERE users.id=:id_1'); $result->execute(array(':id_1' => $id_1)); 

but nothing writes together

 WHERE users.id=:id_1 OR users.id=:id_2'); $result->execute(array(':id_1' => $id_1, ':id_2' => $id_2)); 

below sample code I want to make a comparison of ads

 header('Content-Type: application/json; charset=utf-8'); $idd = $_POST['id']; $result = count($idd); $id = array(); if (count($result) == 1) { $id_1 = (current($idd)); } if (count($result) < 3) { next($idd); $id_2 = (current($idd)); } if (count($result) < 4) { next($idd); $id_3 = (current($idd)); } require_once($_SERVER['DOCUMENT_ROOT'] . '/bd.php'); $result = $pdo->prepare( 'SELECT DISTINCT users.id, users.kl, users.Name, users.sebe, images_ava.catalog_small, images_ava.filename_small FROM users INNER JOIN images_ava ON users.id = images_ava.id WHERE users.id=:id_1 OR users.id=:id_2'); $result->execute(array(':id_1' => $id_1, ':id_2' => $id_2)); if($result->rowCount() > 0){ $myrow = $result-> fetch(PDO::FETCH_ASSOC); do { $file = explode(',', $myrow['filename_small']); foreach ($file as $val) { ; echo json_encode(" <div class='row'> <div class='col-md-10 block-info width'> <div class='col-md-3'> <img src='registration/1/".$myrow['catalog_small'].$val."' class='img-responsive' title='1' alt='1' /> <div class='col-md-3'> ".$myrow['kl']."</div> </div> "); } } while ($myrow = $result->fetch(PDO::FETCH_LAZY)); } else { // Π‘ΠΎΠ±Ρ‰Π΅Π½ΠΈΠ΅ ΠΎ пустой Ρ‚Π°Π±Π»ΠΈΡ†Π΅ print_r ("<p>Π˜Π½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡ ΠΏΠΎ запросу Π½Π΅ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ ΠΈΠ·Π²Π»Π΅Ρ‡Π΅Π½Π°, Π² Ρ‚Π°Π±Π»ΠΈΡ†Π΅ Π½Π΅Ρ‚ записСй.</p>"); exit(); } 

and so through ajax I call him

 $(window).load(function() { //Π³ΠΎΠ²ΠΎΡ€ΠΈΠΌ скрипту Ρ‡Ρ‚ΠΎ ΠΎΠ½ сработаСт ΠΊΠΎΠ³Π΄Π° вся страница загрузится var ID = [];//ΠΎΠ±ΠΎΠ·Π½Π°Ρ‡Π°Π΅ΠΌ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½ΡƒΡŽ для массива $('.btn.btn-primary.btn-lg.width').click(function() {//Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ ID.push($(this).data('id'));//записываСм Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ ΠΊΠ»ΠΈΠΊΠΎΠ² Π² массив console.log(ID); });//Ρ‡Ρ‚ΠΎ Π²Ρ‹Π΄Π°Π΄Π΅Ρ‚ консоль Ρ‚ΠΎΡ‡Π½Π΅Π΅ масив $('.btn.btn-primary.btn-lg.width').click(function(e) { //Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ $("#basket").show("slow"); // ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°ΠΊ откроСтся Ρ„ΠΎΡ€ΠΌΠ° }); // ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°ΠΊ откроСтся Ρ„ΠΎΡ€ΠΌΠ° $('.compare_basket').click(function(e) { //Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ $(".compare_basket").hide("slow"); });// ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°ΠΊ откроСтся Ρ„ΠΎΡ€ΠΌΠ° $('#basket').click(function(e) { //Π»ΠΎΠ²ΠΈΠΌ ΠΊΠ»ΠΈΠΊ $(".compare_basket").show("slow"); console.log(ID); //Ρ‡Ρ‚ΠΎ Π²Ρ‹Π΄Π°Π΄Π΅Ρ‚ консоль $.ajax({ // сам ajax запрос url: "myscript.php", // ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ Π½Π° php data: {id: ID}, // Π΄Π°Π½Ρ‹Π΅ ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ пСрСдатся type: "POST", // ΠΌΠ΅Ρ‚ΠΎΠ΄ success: function(response){ $("#ajaxDivId_1").html(response); }, // Ссли запрос ΡƒΠ΄Π°Ρ‡Π½Ρ‹ΠΉ Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ Ρ‚ΠΎ Ρ‡Ρ‚ΠΎ Π²Π΅Ρ€Π½ΡƒΠ» скрипт php error: function(er){ alert(er); }, // Ссли запрос Π½Π΅ удался Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ ΠΎΡˆΠΈΠ±ΠΊΡƒ }) .done(function(data) { //ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½Ρ‹ΠΉ запрос ΠΏΠΎ ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠΌΡƒ заносятся Π΄Π°Π½Π½Ρ‹Π΅ // Π²Ρ‹Π²ΠΎΠ΄ΠΈΠΌ ΠΎΡ‚Π»Π°Π΄ΠΎΡ‡Π½ΡƒΡŽ ΠΈΠ½Ρ„ΠΎΡ€ΠΌΠ°Ρ†ΠΈΡŽ }); }); }) 

  • Well, if your js code tells you that there is an error in php, it may be worth seeing what is there for the error after all? - Bookin

2 answers 2

I will assume that you have a problem in your do{}while() , put an array in the $myrow variable ( PDO::FETCH_ASSOC ) before the loop, work with the variable as an array, then the condition puts the object there, and works with it as array, there is a suspicion that the script does not like.

For what you use do{}while() I don’t know, but it’s probably easier to use while(){} :

 if($result->rowCount() > 0){ while (($myrow = $result->fetch(PDO::FETCH_ASSOC))){ $file = explode(',', $myrow['filename_small']); foreach ($file as $val) { echo json_encode(" <div class='row'> <div class='col-md-10 block-info width'> <div class='col-md-3'> <img src='registration/1/".$myrow['catalog_small'].$val."' class='img-responsive' title='1' alt='1' /> <div class='col-md-3'> ".$myrow['kl']."</div> </div> "); } } } 

You also have after foreach ($file as $val) { mysterious semicolon - ; perhaps there is a typo, but it should not be there.

    and tried to use bindParam () and / or bindValue ()? (Yusai square brackets of the array) Although it should work (like yours), try anyway))

    • Sori displays this here if you add two error: function (er) {alert (er); } that the request does not pass - Koly
    • Add a json and javascript theme tag (now the people rushing through JS will be pulled up) - Sergey SHevchenko