Ajax get data only first item in while loop

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…?

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?

Is that inner join is wrong…?

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.

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

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

$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;

But it will also get first value only in ajax…

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

 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;
		 
	}
});
}

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

PHP:

Ajax:

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…

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.

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.

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

Sponsor our Newsletter | Privacy Policy | Terms of Service