473,385 Members | 2,269 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,385 software developers and data experts.

Display image from database

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, 253 views)
Jun 14 '10 #1
9 2822
Banfa
9,065 Expert Mod 8TB
Line 17 of My bulletinImage.php, shouldn't that be

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

?
Jun 14 '10 #2
chabbs
5
@Banfa
Ok thank you.

And any idea for the other part of the query?
Jun 14 '10 #3
chabbs
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
424 256MB
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
chabbs
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
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. <select name="names1" id="names" onchange="imageDetails()">
  2. ...
  3. </select>
  4.  
Jun 15 '10 #7
johny10151981
1,059 1GB
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
424 256MB
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
chabbs
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

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

Similar topics

1
by: Tan | last post by:
Hi I am desperate for any help with display image in Gridview I have a gridview contain surname , forename ..... and image. I could not display image as my database store the column image as...
3
by: harish | last post by:
Hi friends I am facing problem as follow I can't display image from SQL Database to Picture box Control. Here are the codes that I am writing Dim arrPicture() As Byte = _
2
by: RedSouljaz | last post by:
Hi, How to display image that was saved in database ms sql server 2000 into picture box. The field type that I use in database is Images I can save to database but cannot show from database. ...
2
by: David | last post by:
I am trying to get an image to appear on all Mondays within the calendar control. I also want that image to be a link. How can I do this?
3
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
7
by: eholz1 | last post by:
Hello Group, Perhaps you can help me. I have a mysql db, that holds images. Images are encoded using base64_decode/encode, etc. Image data seems fine. I have a view.php page that is supposed...
7
by: alexseow | last post by:
Query.asp <%@ LANGUAGE="VBSCRIPT" %> <!-- #include file="../../includes/dbconn.asp"--> <% dim MyRs, sqlstr, MyConn Response.Expires = 0 Response.Buffer = TRUE Response.Clear
1
by: shalini328 | last post by:
I am using ASP.net 1.1 C# and database is MS access.Can you tell me how can i display image from database
1
by: saadkhan | last post by:
I want to display image in <img> tag using database. I just need to know that how could i be able to define path or whatever to <img> tag. I have no probem in making queries to database.....plz help
5
by: SafaaDalloul | last post by:
Please I want know How I can Display Image from database randomly when the web page refresh in Asp.net by C# code
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.