kaseencook Posted May 20, 2009 Share Posted May 20, 2009 Hello and thanks for viewing! Our website collects form data with an HTML form and sends it to a PHP script that processes it and sends it to a MySQL Datbase. Then on a search page, users can search and sort from the data in the MySQL database using a PHP code generated by PHP Generator from Meastro. One of the fields in the database is a link to an image and should display an image from an image hosting website or some other website. I don't seam to be able to get the image display to work though, it just shows a broken image. The page is here http://www.ccaretta.com/form_data.php, and the last two enries should show images. I have formatted one image as <img src="http://www.yoursite.com/image.jpg"> and one as just http://www.yoursite.com/image.jpg record entries in the MySQL database to see if it was a matter of formatting the image link, but neither work. The code is rather long, but this is the image part of the code: <?php function showrow($row, $recid) { ?> <table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%"> <tr> <td class="hr"><?php echo htmlspecialchars("Image")." " ?></td> <td class="dr"><?php echo outimage($recid, "imageurl", "", "200", "200") ?></td> </tr> Does anyone know how this should be formatted to display images that are in the form of a URL? Or how the image URL should be formatted when inserted into the database? Thanks so much for any suggestions! Quote Link to comment https://forums.phpfreaks.com/topic/158874-solved-displaying-image-from-link-in-php/ Share on other sites More sharing options...
kaseencook Posted May 20, 2009 Author Share Posted May 20, 2009 Also, the part of the code that is like this: outimage($recid, "imageurl", "", "200", "200") Has those empty "" in the middle for the $alt perameter, but I don;t know what alt is? What is alt, and do I need it? Could this be the issue? Also could it be the "outimage" command? Does this only display images and not images via links? I have looked all over the internet and can't find anything on a related topic, Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/158874-solved-displaying-image-from-link-in-php/#findComment-837943 Share on other sites More sharing options...
GingerRobot Posted May 20, 2009 Share Posted May 20, 2009 Ok, so you're storing this text in the database: "<img src="http://www.yoursite.com/image.jpg">" ? You don't want to be doing that...just store "http://www.yoursite.com/image.jpg" Obviously without knowing what the outimage function does, it's a bit difficult. However, the alt parameter is for alternate text - the text you might see if you hover over images. It's for accessibility. The easiest way to work out what's going wrong is to take a look at the generated HTML. View the source of the page and see what images are supposed to be being displayed. I couldn't actually see any broken images on the page you posted. Quote Link to comment https://forums.phpfreaks.com/topic/158874-solved-displaying-image-from-link-in-php/#findComment-837950 Share on other sites More sharing options...
kaseencook Posted May 20, 2009 Author Share Posted May 20, 2009 Thanks for the reply, viewing the html of the output is helping me to understand what the script is doing. This is what the html output for the image that is supposed to be displayed: <tr> <td class="hr">Image </td> <td class="dr"><img src="test_images.php?getimage=5&field=imageurl" border=0 alt="" width="200" height="200"></td> </tr> Obviously instead of inserting the link to the image it has inserted "test_images.php?getimage=5&field=imageurl"...... humm.... what is making it insert that string instead of the image URL, perhaps it is the "outimage" command? I would think that if the out put for the image was formated like any other simple text output that it would just show the URL and not the image. Are there other commands that would display the URL as an image? Thanks for the info on the alt and your help, it is very much appreciated, novices like me wouldn't be able to do cool things in code without the generous help of others on these forums! Quote Link to comment https://forums.phpfreaks.com/topic/158874-solved-displaying-image-from-link-in-php/#findComment-838059 Share on other sites More sharing options...
trq Posted May 20, 2009 Share Posted May 20, 2009 what is making it insert that string instead of the image URL, perhaps it is the "outimage" command? We wouldn't know without seeing the code that does the INSERT. There is no "outimage" command (function) built into php, so maybe we should see that too. Quote Link to comment https://forums.phpfreaks.com/topic/158874-solved-displaying-image-from-link-in-php/#findComment-838060 Share on other sites More sharing options...
kaseencook Posted May 21, 2009 Author Share Posted May 21, 2009 ah Ha! After a light bulb to search through the big PHP code to find the definition of this "outimage", I found where "outimage" is defined. So this part defines the outimage: }function outimage($recid, $field, $alt, $width, $height) { $res = "<img src=\"test_images.php?getimage=$recid&field=$field\" border=0 alt=\"$alt\""; if ($width <> '') $res = $res." width=\"$width\""; if ($height <> '') $res = $res." height=\"$height\""; $res = $res.">"; return $res; } This was the code part that was supposed to display the image via a url in a table with the "outimage": <tr> <td class="hr"><?php echo htmlspecialchars("Image")." " ?></td> <td class="dr"><?php echo outimage($recid, "imageurl", "", "200", "200") ?></td> </tr> And this is the resulting html of the output when doing a "view source" on the results page: <tr> <td class="hr">Image </td> <td class="dr"><img src="test_images.php?getimage=7&field=imageurl" border=0 alt="" width="200" height="200"></td> </tr> It looks like the "test_images.php?getimage=$recid$field=$field" is being echoed into the image tags instead of the url from the "imageurl" field that contains the html code. Going on this, I tried to replace that string with different things, such as with the $field, but it only seems to out put the actual name of the field (imageurl) and not the contents of the field (example below): <tr> <td class="hr">Image </td> <td class="dr"><img src=".imageurl." border=0 alt="" width="200" height="200"></td> </tr> I tried a bunch of other combinations but nothing worked...... Any ideas of what I could replace the "test_images.php?getimage=$recid$field=$field" within the definition of the "outimage" function to make it display the contents of "imageurl" field within the image tags? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/158874-solved-displaying-image-from-link-in-php/#findComment-838919 Share on other sites More sharing options...
kaseencook Posted May 22, 2009 Author Share Posted May 22, 2009 Solved!! Ha ha! I changed the outimage function to this: }function outimage($recid, $href, $alt, $width, $height) { $res = "<img src=\"$href\" border=0 alt=\"$alt\""; if ($width <> '') $res = $res." width=\"$width\""; if ($height <> '') $res = $res." height=\"$height\""; $res = $res.">"; return $res; } and the php that displays the image to this: <tr> <td class="hr"><?php echo htmlspecialchars("Image")." " ?></td> <td class="dr"><?php echo outimage($recid, htmlspecialchars($row["imageurl"]), "", "200", "200") ?></td> </tr> Thanks for you help, it led me to realise that I needed to redefine the function, but I didn't know how as I kept getting the formating wrong, but I found some good tutorial on defining functions and eventually figured out what went where and used another function that displays url's as links as a template, and success! Quote Link to comment https://forums.phpfreaks.com/topic/158874-solved-displaying-image-from-link-in-php/#findComment-839536 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.