By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,354 Members | 596 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,354 IT Pros & Developers. It's quick & easy.

Display image from database

P: 5
Hi,

I have my form with some combo box and radio button.

And i need to display an image based on the selections.

I need to display dynamically the image when the selections are made without any submit button.

The image comes from a table where it needs to be retrieved from the selection criteria.

I have my form but i am not able to get the data from the form to display the image.

Can anyone help??

Thanking you.

My page with radio button and combo box

e.g to display maps, selection is 1
My main page.php

Expand|Select|Wrap|Line Numbers
  1. <tr id="displayType1" class=hide>
  2. <td><font color="#FFFFFF">
  3. <form name="displayType">
  4. <Input type = 'Radio'
  5. Name ='display' 
  6. value= '1'
  7. onclick="displayMaps();"
  8. id='idMaps'>
  9. Maps
  10. <Input type = 'Radio' 
  11. Name ='display' 
  12. value= '2'
  13. id='idSections'
  14. checked
  15. onclick="displaySection();">
  16. Sections<br>                
  17. <Input type = 'Radio' 
  18. Name ='display' 
  19. value= '3' 
  20. id='idAnimation'
  21. onclick="displayAnimation();">
  22. Animations
  23. </form>
  24. </font>
  25. </td>
  26. <!--the image is displayed in the corresponding td-->
  27. <td>
  28. <img src="bulletinImage.php?id=<php echo $id ?>">
  29. </td>
  30. </tr>
My bulletinImage.php - for the display of the image
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $con = mysql_connect("localhost","root","");
  4. if(!$con)
  5. {
  6. die('Could not connect: ' . mysql_error());
  7. }
  8. mysql_select_db("ocean",$con);
  9.  
  10. //This query is static, its here that i shall put the select query from the data selected on the previous page main.php
  11.  
  12. $query = "SELECT outputMap FROM globalStructure WHERE id = 1";
  13. $result = mysql_query($query) or die('Error, query failed');
  14. //$result = mysql_query($_POST['ScreenResolution']) or die('Error, query failed');
  15. $content=mysql_result($result,0,"outputMap");
  16. //send pdf to requesting page
  17. header("Content-type: outputMap/jpg");
  18. echo $content;
  19. ?>
Waiting for your reply
Thanking you.
Attached Images
File Type: jpg home.jpg (22.8 KB, 227 views)
Jun 14 '10 #1
Share this Question
Share on Google+
9 Replies

Banfa
Expert Mod 5K+
P: 8,971
Line 17 of My bulletinImage.php, shouldn't that be

header("Content-type: image/jpg");

?
Jun 14 '10 #2

P: 5
@Banfa
Ok thank you.

And any idea for the other part of the query?
Jun 14 '10 #3

P: 5
I did make some changes in my codes for the display of the image.

Now am getting the image with the selection criteria from the database correctly. But my problem is, i need to have a submit button for the image to be shown. And in my requirement, i shall not have any submit button, upon selection of the e.g region as shown on the image, i shall have the corresponding image from the database to my screen.

Anybody know how to send these data to the php script without the submit button?

Find below the codes that i have for all pages an using.

- My main.php (page with combo box)
Expand|Select|Wrap|Line Numbers
  1. <!-- table row of combo box-->
  2. <tr>
  3. <td><font color="#FFFFFF"><b>Region:</b></font><br>
  4. <form name="region">
  5. <select name="names1" id="names">
  6. <?php
  7. while($fetch = mysql_fetch_assoc($query)){
  8. echo "<option value=".$fetch['id'].">".$fetch['regionName']."</optgroup>";
  9. }
  10. ?>
  11. </select>
  12. </form>
  13. </td>
  14. </tr>
  15. .
  16. .
  17. .
  18. .
  19. .
  20. <!--My table data to place image -->
  21. <tr>
  22. <td></td>
  23. <td rowspan='2'>
  24. <?php
  25. echo "<form name=\"formImage\" method=\"post\" >
  26. <input name=\"imageResolution\" id=\"idImageQuery\" type=\"hidden\"/>
  27. <input name=\"ScreenResolution1\" type=\"submit\" value=\"Submit\" onclick=\"imageDetails()\"/>
  28. </form>";
  29. $dataQuery = $_POST['imageResolution'];
  30. $dataQuery = $_POST['imageResolution'];
  31. echo $dataQuery;*/
  32. echo "<img src=\"bulletinImage.php?img={$dataQuery}\">";
  33. ?>
  34. </td>
  35. </tr>
  36.  
-Javascript function imageDetails() used in the submit button

Expand|Select|Wrap|Line Numbers
  1. function imageDetails() {
  2. //var finalConcat = 'SELECT * FROM globalstructure WHERE';
  3. var region = document.region.names1.value;//id of region e.g = 1
  4. var finalConcat = region+",";
  5. //finalConcat += ' regionId = '+region;
  6. var analysisDate = document.analysisDate.analysisDate1.value;//id of date e.g = 1            
  7. finalConcat += analysisDate+",";
  8. .
  9. .
  10. .
  11. .
  12. return document.formImage.imageResolution.value = finalConcat;
  13. }
  14.  

- My page to get the image from database bulletinImage.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if(!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8. $img = $_REQUEST["img"];
  9. list($region, $date, $displayType, $analysis, $parameter, $depth) = split('[,]', $img);
  10. mysql_select_db("ocean",$con);
  11.  
  12. $query = "SELECT outputMap FROM globalStructure WHERE regionId = ".$region .
  13. " AND analysisDateId = ".$date.
  14. " AND displayStructure = ".$displayType.
  15. " AND analysisType = ".$analysis.
  16. " AND parameter = ".$parameter.
  17. " AND depth = ".$depth.
  18. "";
  19.  
  20.  
  21. //$query = @mysql_query("SELECT * FROM globalStructure WHERE id=" . $img . "");
  22. $result = mysql_query($query) or die('Error, query failed');
  23. //$result = mysql_query($_POST['ScreenResolution']) or die('Error, query failed');
  24. $content=mysql_result($result,0,"outputMap");
  25. //send pdf to requesting page
  26. header("Content-type: image/jpg");
  27. echo $content;
  28. ?>        
  29.  
My image is displayed, but only after i click the submit button. And i need to have the image just after i select a region without any button click.

Anybody?? Its urgent. Shall have ended this today.
Jun 15 '10 #4

anfetienne
100+
P: 424
add an onchange="" to the selection boxes...


i've just quickly had a look at it but if you want to do it on selection then use the below on the form fields instead of onclick on a submit button

Expand|Select|Wrap|Line Numbers
  1. onchange=\"imageDetails()\"
  2.  
Jun 15 '10 #5

P: 5
Hi

Can you please give me the full codes of how to put that onchange in the select section??

Expand|Select|Wrap|Line Numbers
  1. <select name="names1" id="names"> 
  2. <?php 
  3. while($fetch = mysql_fetch_assoc($query)){ 
  4. echo "<option value=".$fetch['id'].">".$fetch['regionName']."</optgroup>"; 
  5. ?> 
  6. </select>
  7.  
Jun 15 '10 #6

Banfa
Expert Mod 5K+
P: 8,971
Expand|Select|Wrap|Line Numbers
  1. <select name="names1" id="names" onchange="imageDetails()">
  2. ...
  3. </select>
  4.  
Jun 15 '10 #7

100+
P: 1,059
you can try this
onchange call a the function that would send your selected data to a certain php page. Send data as post method or get method. and the php page will process all the data and return a formatted message that will describe
1. return the successful message and also return the name of the required file name querying from database
or
2. failure message.

after getting successful message simply assign the img src with the returned image name with qualified path.
do it all using AJAX. its simple
Jun 16 '10 #8

anfetienne
100+
P: 424
he already has his function that works and only needs to use it in a onchange... there is no need for him to write an ajax code
Jun 16 '10 #9

P: 5
How can i post my data in another php page if i didnot use the submit button below?

[code]
<?php
echo "<form name=\"formImage\" method=\"post\" >
<input name=\"imageResolution\" id=\"idImageQuery\" type=\"hidden\"/>
<input name=\"ScreenResolution1\" type=\"submit\" value=\"Submit\" onclick=\"imageDetails()\"/>
</form>";
$dataQuery = $_POST['imageResolution'];
echo "<img src=\"bulletinImage.php?img={$dataQuery}\">";
?>
[code]
Aug 10 '10 #10

Post your reply

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