473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

display images from db using jquery

pradeepjain
563 512MB
hii,
I have 3 images for a single id like 00024 in the DB. when ever the user selects the ID from the drop down .all the 3 images must be displayed . how do i do this?

this is the image script i use and display images like
<img src='/diabetes/visitimages/thumbpicdisplay.php?id=<?php echo $id ?></img>
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include_once('../db.php');
  4.  
  5.         $sql = "SELECT image FROM rop_images WHERE Patient_id='".$_GET['id']."'";
  6.  
  7.         $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
  8.  
  9.         header("Content-type: image/jpeg");
  10.         $test=mysql_result($result,0);
  11.  
  12. $desired_width  =  80;
  13. $desired_height  =  80;
  14.  
  15. $im  =  imagecreatefromstring($test);
  16. $new  =  imagecreatetruecolor($desired_width,  $desired_height);
  17.  
  18. $x  =  imagesx($im);
  19. $y  =  imagesy($im);
  20.  
  21. imagecopyresampled($new,  $im,  0,  0,  0,  0,  $desired_width,  $desired_height,  $x,  $y);
  22.  
  23. imagedestroy($im);
  24. header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  25. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past 
  26. header('Content-type:  image/jpeg');
  27. imagejpeg($new,  NULL,  85);
  28.  
  29. imagedestroy($new);
  30. //      echo $test;
  31.  
  32.         mysql_close($link);
  33. ?>
  34.  
Mar 11 '10 #1
8 8323
Atli
5,058 Expert 4TB
Hey.

How do you differentiate between the three images?

Generally, though, you would just pass ALL the identifiers required to query the specific image from the database, and have the script fetch and display it.
Expand|Select|Wrap|Line Numbers
  1. <img src="getimg.php?parent_id=1&size=32" alt="32 px thumb">
  2. <img src="getimg.php?parent_id=1&size=64" alt="64 px thumb">
  3. <img src="getimg.php?parent_id=1&size=128" alt="128 px thumb">
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $parent_id = (int)$_GET['parent_id'];
  3. $thumb_size = (int)$_GET['size'];
  4.  
  5. if($parent_id > 0 && $thumb_size > 0)
  6. {
  7.     $sql = "SELECT `data`, `mime` 
  8.             FROM `thumbs`
  9.             WHERE `parent_id = {$parent_id}
  10.             ADN   `size` = {$thumb_size}"
  11.  
  12.     // etc...
  13. }
  14. ?>
See what I mean?
Mar 11 '10 #2
pradeepjain
563 512MB
yeah that was the way i was doing .

Now the requirement is that we have to display all the images from Db regarding a Id.So we have a dropdown with all the Id's . when the user changes the ID the images from get displayed .
since i am using jquery . i asked this question how do i do using jquery and another problem is that . there can be any number of images corresponding to a ID say ( 0006) .
Mar 11 '10 #3
pradeepjain
563 512MB
i have a small idea on this . please help me executing this using jquery.

when ever the dropdown is changed , i call a function and i fetch the rowid(auto incremented value) and actual id from the Db . and make it into a array in a php file and then return it back in a array to the jquery .

like
Expand|Select|Wrap|Line Numbers
  1. ("#dropdown").change(function(){
  2.                 $.post("change.php",{ state:$("#id").val()} ,function(data){
  3.  
  4. // get the count count(array) so that we know number of images .
  5. //loop through the array and print the images
  6. // how do i do the previous 2 steps ? 
  7. // instead of state:$("#id").val() can i pass value like state: <?php echo $id ?> ??
  8. });
  9.     });
Mar 12 '10 #4
pradeepjain
563 512MB
no help on this problem ?
Mar 15 '10 #5
pradeepjain
563 512MB
Expand|Select|Wrap|Line Numbers
  1. $.post("/diabetes/ropimages/getcount.php",{pid:$("#patient_id").val()} ,function(data1){
  2. //alert(data1);
  3. var count = data1;
  4. var pid = $("#patient_id").val();
  5. var rid;
  6. for( var i = 1 ; i <= count ; i++)
  7. {
  8. var link ='<img src="/diabetes/ropimages/thumbpicdisplay.php?pid=+pid+&rid=1" />';
  9. $("#content1").empty().html(link);
  10. }
  11. });
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
Mar 15 '10 #6
pradeepjain
563 512MB
i finally wrote code like this..



Expand|Select|Wrap|Line Numbers
  1. $.getJSON("/diabetes/ropimages/getcount.php",{pid:$("#patient_id").val()} ,function(data1){
  2.  
  3. var i;
  4. var count = data1.count;
  5.  
  6. var start = data1.start;
  7.  
  8. var pid = $("#patient_id").val();
  9.  
  10.  
  11. for(i = start ; i <= count ; i++)
  12. {
  13. var link ='<a href="/diabetes/ropimages/origpicdisplay.php?pid='+pid+'&rid='+i+'"><img src="/diabetes/ropimages/thumbpicdisplay.php?pid='+pid+'&rid='+i+'"/><a>';
  14. alert(link);
  15. if(i > start)
  16. {
  17. $("#content1").append(link);
  18. }
  19. else{
  20. $("#content1").empty().html(link);
  21. }
  22.  
  23. }
  24. },"Json");
for the 1st loop it works ..then it stops printing the images...can u just tell me whts the problem? its not coming inside the loop itself, i checked giving the alert statement inside the loop.
Mar 15 '10 #7
Markus
6,050 Expert 4TB
Moving to JavaScript.
Mar 15 '10 #8
pradeepjain
563 512MB
finally i solved the problem by writing code like this.

Expand|Select|Wrap|Line Numbers
  1. $("#patient_id").change(function(){
  2.  
  3. $.getJSON("/diabetes/ropimages/getcount.php",{pid:$("#patient_id").val()} ,function(data1){
  4.  
  5.  
  6. var link = "";
  7.  
  8. var count = parseInt(data1.count);
  9. var start = parseInt(data1.start);
  10. var pid = $("#patient_id").val();
  11.  
  12.  
  13. count = parseInt(count)+parseInt(start);
  14.  
  15. if(count > 0){
  16. for(var i= parseInt(start); i < parseInt(count); i++)
  17. {
  18.  
  19. link ='<a href="/diabetes/ropimages/origpicdisplay.php?pid='+pid+'&rid='+i+'"><img src="/diabetes/ropimages/thumbpicdisplay.php?pid='+pid+'&rid='+i+'"/><a>';
  20.  
  21. if(i > start){ $("#content1").append(link);}
  22.  
  23. else{ $("#content1").empty().html(link);}
  24. }
  25. }
  26. else{ $("#content1").html("No Images uploaded");}
  27. },"Json");
  28.  
  29. });
Mar 17 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page...
6
by: Gale | last post by:
I'm working on something in jQuery with XPath What I want to do is: if checkbox is checked, set background color od label that contain input(checkbox) to red I have this code:...
5
by: ziobudda | last post by:
Hi, I want ask you if, for a web portal/application, is better prototype or Jquery? I don't want to innesc some type of flame, but after the announce that drupal use JQuery and that the new...
2
by: darrel | last post by:
I'm still struggling to find a javascript/ajax library that I want to stick with for a while. JQuery is looking great these days...refined, LOTS of plug-ins, and an active community. Is...
1
by: DuaneMoraes | last post by:
A new book on jQuery, the powerful JavaScript library, has been announced by Packt In Learning jQuery, Karl Swedberg and Jonathan Chaffer, creators of the popular jQuery learning resource...
1
by: mikeh3275 | last post by:
I'm new to developing in jQuery, so I'm probably doing this wrong. I'm loading a form into a modal dialog box and I'm trying to assign a click event to the button in the form, but I can't seem to...
83
by: liketofindoutwhy | last post by:
I am learning more and more Prototype and Script.aculo.us and got the Bungee book... and wonder if I should get some books on jQuery (jQuery in Action, and Learning jQuery) and start learning about...
26
by: RobG | last post by:
Do some of the regulars here need to re-think their (sometimes strident) opposition to libraries? Both Microsoft and Nokia have announced support for jQuery. It seems to have gained quite a bit...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
4
by: pavanip | last post by:
Hi, I want to popup aspx page using jquery. I have written the following code <a href="Contactus.aspx?TB_iframe=true&height=250&width=200" class="thickbox" >AboutUs</a> I have called...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.