Jump to content

Newbie Help.


daleGT

Recommended Posts

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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  . '">';
Link to comment
Share on other sites

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>";
}
?>
Link to comment
Share on other sites

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 by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.