daleGT Posted May 2, 2015 Share Posted May 2, 2015 Hey People! I'm saving & uploading images from a form into a data table. the image name is being changed into "datetime_imagename.jpg" when i select multiple images they are comma seperated. what is the best way to display these? I'm ok with a single image but multiple im struggling finding much info online. (doubt i know enough to find what im looking for) Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 2, 2015 Share Posted May 2, 2015 You should change your table structure to store ONE and only ONE image name in a table column. If you have multiples of them for a single user/date, etc you need to have an "image table" just to store the names, all linked back to that user/date, etc. Never store data in a table as a comma-separated value. Quote Link to comment Share on other sites More sharing options...
daleGT Posted May 2, 2015 Author Share Posted May 2, 2015 the names of the images wont conflict. it does go date/time/minute/second. Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 3, 2015 Share Posted May 3, 2015 When people don't provide code, we can only call out things that sound hinkey. Regardless, you are complicating something that is simple. You display images in a browser using the img tag. Whether you stored one image file or many in a specific row, that is not going to change the fact that each individual image you want to display on a web page has to be available in the src= param of the the img tag. With that said, as ginerjm advised, it's a lot easier to write an img helper script if you have a solid table structure with one image per row referenced. Then you tend to write something like: // getimg.php $id = (int)$_GET['id]; $sql = "SELECT * FROM images WHERE id = $id"; //query for image row if ($found) { $fp = fopen($row['filepath'], 'rb'); //Determine right header -- jpeg example here // .... $imgMimeType = 'image/jpeg'; header('Content-Type: ' . $imgMimeType); header("Content-Length: " . filesize($row['filepath'])); fpassthru($fp); exit; } else { //return data for default img. Remember this is returning image data, so you have to return a valid image. } Then of course where you want to display the images you will have markup like this in your output script: echo '<img src="getimg.php?id=' . $images_id . '">'; Quote Link to comment Share on other sites More sharing options...
daleGT Posted May 3, 2015 Author Share Posted May 3, 2015 I'm using a joomla product call chronoforms attempting to save each file name seperatly into field14/15/16 etc now. The above is over my head. I had done the below code a few years back (basic but worked) i updated a program called "jumi" and it now no longer works <?php DEFINE ('DB_USER', 'username'); DEFINE ('DB_PSWD', 'password'); DEFINE ('DB_HOST', 'localhost.site.com'); DEFINE ('DB_NAME', 'username'); $dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME); if (!$dbcon) { die('error connecting to database'); $sqlget = "SELECT * FROM `xtgt` ORDER BY `VIN` ASC"; $sqldata = mysqli_query($dbcon, $sqlget) or die('error getting'); } echo ''; $sqlget = "SELECT * FROM `xtgt` ORDER BY `VIN` ASC"; $sqldata = mysqli_query($dbcon, $sqlget) or die('error getting'); while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) { Echo "<b>Build Number:</b><br> ".$row['VIN'] . " <br>"; Echo "<b>Engine Code:</b> ".$row['engine'] . " <br>"; Echo "<b>Trim Code:</b> ".$row['trim'] . " <br>"; Echo "<b>Trans Code:</b> ".$row['trans'] . " <br>"; Echo "<b>Paint Code:</b> ".$row['paint'] . " <br>"; Echo "<b>Tyre Code:</b> ".$row['tyre'] . " <br>"; Echo "<b>Dealer Code:</b> ".$row['dealer'] . " <br>"; Echo "<b>Factory Options:</b> ".$row['options'] . " <br>"; Echo "<b>Details/Comments:</b> ".$row['comments'] . " <br>"; $image1 = "[url=http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/]http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/[/url]".$row['file14'] ."<br>"; $size = getimagesize("$image1"); $height = $size[1]; $width = $size[0]; if ($height > 150) { $height = 150; $width = 190; } else if ($width > 150) { $height = 150; $width = 190; } Echo "<a href=\"[url=http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/]http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/[/url]".$row['file14'] ."\"> <img src=\"[url=http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/]http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/[/url]".$row['file14'] ."\" height=\"150\" width=\"190\" border=0 alt=\"" . $row['input_upload1'] . "\"> </a>" ; Echo "<a href=\"[url=http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/]http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/[/url]".$row['file15'] ."\"> <img src=\"[url=http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/]http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/[/url]".$row['file15'] ."\" height=\"150\" width=\"190\" border=0 alt=\"" . $row['input_upload2'] . "\"> </a>" ; Echo "<a href=\"[url=http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/]http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/[/url]".$row['file16'] ."\"> <img src=\"[url=http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/]http://www.site.com/components/com_chronoforms5/chronoforms/uploads/xtgt/[/url]".$row['file16'] ."\" height=\"150\" width=\"190\" border=0 alt=\"" . $row['input_upload3'] . "\"> </a>" ; Echo "<b></b> ".$row[''] . " <br>"; Echo "<b></b> ".$row[''] . " <br>"; } ?> Quote Link to comment Share on other sites More sharing options...
daleGT Posted May 3, 2015 Author Share Posted May 3, 2015 They are currently still saving comma seperated into file14.! Input_upload1/2/3 are file14/15/16 I noticed that after i had posted the forum won't allow me to edit it. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 3, 2015 Share Posted May 3, 2015 (edited) I have no idea what your last two posts are talking about. I will offer my usual tips: 1 - turn on php error checking 2 - separate your logic (your php code) from your output (your html code). Makes it easier to read and to maintain 3 - Try and write your questions in clear language and use punctuation so that we can interpret what you are trying to tell us better. 4 - Learn how to spell the word 'separately'. I still stand by my original post - do not store multiple items in one field. That is not how databases are used. Edited May 3, 2015 by ginerjm Quote Link to comment 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.