0
$.post("/diabetes/ropimages/getcount.php",{pid:$("#patient_id").val()} ,function(data1){
  //alert(data1);
  var count = data1;
  var pid = $("#patient_id").val();
  var rid;

  for( var i = 1 ; i <= count ; i++) {
    var link ='<img src="/diabetes/ropimages/thumbpicdisplay.php?pid=+pid+&rid=1" />';
    $("#content1").empty().html(link);
  }
});

I am trying to pass pid value in url ..but its taking directly as +pid+ as value ..how do i give it the value of pid.

And how do i print 3 images in a div? like the one in code

1 Answer 1

3

You simply need to terminate the string after ?pid= and then use the concatenation operator (+) to "insert" the pid variable in the appropriate location:

'<img src="/diabetes/ropimages/thumbpicdisplay.php?pid=' + pid + '&rid=1" />'

As for attaching the 3 images to the div, you might have more luck doing the following:

var link = '';

for(var i = 1; i <= count; i++) {
   link += '<img src="...thumbpicdisplay.php?pid=' + pid + '&rid=1" />';
}

$("#content1").empty().html(link);
Sign up to request clarification or add additional context in comments.

5 Comments

hey i wrote code like this... for 1st loop it works then it stops working can u just tell me where i am going wrong
$.getJSON("/diabetes/ropimages/getcount.php",{pid:$("#patient_id").val()} ,function(data1){ var i; var count = data1.count; var start = data1.start; var pid = $("#patient_id").val(); for(i = start ; i <= count ; i++) { var link ='<a href="/diabetes/ropimages/origpicdisplay.php?pid='+pid+'&rid='+i+'"><img src="/diabetes/ropimages/thumbpicdisplay.php?pid='+pid+'&rid='+i+'"/><a>'; alert(link); if(i > start) { $("#content1").append(link); } else{ $("#content1").empty().html(link); } } },"Json");
@pradeep: What value of count are you getting?
i am getting start value as 6 and count as 3 .when i try to add those 2 like count = count+start; and print it ..it gives like 36 instead of 9 . i think its taken it as string ..how to solve this prob?
you can use parseInt(count) + parseInt(start) to avoid that problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.