Ajax get data only first item in while loop

#1

Hai,

i am using ajax to get looping value but it will get first value only …

  $sql = 'SELECT * from booking_master
  INNER JOIN   *****
  WHERE booking_master.user_id=:id';

  $query = $conn->prepare($sql);
  $query->bindParam(':id', $id);

  $query->execute();

  if($query->rowCount())
  {

       while($row11 = $query->fetch(PDO::FETCH_ASSOC))
       {   ?> 
      <tr>
      <td> <?php echo $row11['user_name']; ?> </td> 
      <input type="hidden" name="userid" id="userid" value="<?php echo $row11['user_id']; ?>">
      <input type="text" value="<?php echo $row11['plot_id']; ?>"  name="plotid" id="plotid">
      <td> <a href="#"  onclick="functscheme()" > Select Plot</a>
     </tr>
    <?php 
       }
     } 

is there any suggestion please…?

#2

I don’t know how many times I have to say NOT to do this.

Is there more than a single record in the table for booking_master that match that id AND have something in the table that you are redacting?

#3

Is that inner join is wrong…?

#4

You should never do select * first of all. And I don’t know what’s going on with the join, since you feel the need to hide it.

#5

it is a problem to Ajax get data only first item in while loop…?

but query working properly…i will got all valid data…

#6
$result = $query->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $row11):  ?> 
      <tr>
      <td> <?php echo $row11['user_name']; ?> </td> 
      <input type="hidden" name="userid" id="userid" value="<?php echo $row11['user_id']; ?>">
      <input type="text" value="<?php echo $row11['plot_id']; ?>"  name="plotid" id="plotid">
      <td> <a href="#"  onclick="functscheme()" > Select Plot</a>
     </tr>
<?php endforeach;
#7

But it will also get first value only in ajax…

#8

Then what is the ajax code and how are you outputting the response?

#9
 function fun1()
 {
  var id2=document.getElementById('userid').value;
  //alert(id2);
  $.ajax({
	url:'shortlist.php?id='+id2,
	complete:function(data)
	{
		document.getElementById('abc1').innerHTML=data.responseText;
		 
	}
});
}
#10

Do a screen shot of the query you are using and the data it returns in PHP MyAdmin

#11

PHP: doubt

Ajax: doubt2

So Here alert(id2); will show first usrid222 only …, in that loop four user are there

ex: userid: 22
23
24
25

but if click userid 24 also getting 22 userid…

#12

You are using the session value, so it will never change. And I asked for pictures of the query and result set from the database, not pictures of the code.

#13

Actually, the OP’s 1st sql query is using !=, so he could be getting more than one user’s output.

The problem is because DOM ids must be unique. ALL the id=’…’ attributes you have in your html markup must be different values.

#14

Actually i am getting 4 records (output)
but we have to show only one id right…, why because it is a loop…