Main
Index
Search
Posts
Who's
Online
Log
In

Home: Discontinued/Classic Products: Instant Website: Realty/Listings/Auto:
Multiple image file names in one database field

 

 


Pixels & Beats
User

Dec 7, 2009, 4:51 AM

Post #1 of 4 (5690 views)
Shortcut
Multiple image file names in one database field Can't Post

Hello CMSB gurus,

All data in my database is automatically imported each night from a CSV file. An SQL is then executed on the data to sort it out to match most of the CMSB auto listing database structure. Everything works great (which is testament to the flexible / robust nature of CMSB) except for one issue.

Due to the constraints of the import process, the image file names part of the CSV file data, are stored in an odd way in the _uploads part of the database.

All image file names are stored in the same field (we will use thumbUrlPath as an example in this case), but they are comma delimited/separated. For example:

000012180_DY02EEG_1908340_MB_391.jpg,000012180_DY02EEG_1908340_IB_082.jpg,000012180_DY02EEG_1908340_IB_334.jpg,000012180_DY02EEG_1908340_IB_646.jpg

This obviously causes a problem when trying to display images with the code:
echo $upload['thumbUrlPath']

When there is only one image there is no problem and all works fine.

In case you are wondering about how it knows the actual path to the file, I have added a field to the database to tell it what the actual path is (in this example we will call it "realUrlPath"), then I join to 2 echo results together to form a whole URL. For example:

<img src="<?php echo $upload['realUrlPath'];echo $upload['thumbUrlPath'] ?>" .......

So my problem is how to work with the comma delimited file names. I am hoping that it can be done with some PHP. As all other routes seem to be failing...

To pre-empt any suggestions I cannot do the following:

1 - Get the data sent to me using a different structure (I really wish they would just do that)
2 - Automatically manipulate the data when in CSV form
3 - Edit the data by hand (would take far too much time)
4 - Use SQL to separate the data into new fields to use the thumbUrlPath2 fields etc (apparently there is no easy way to do this in SQL, I have tried asking in various places including my Expert Exchange account)

I am not a programmer but really a web / graphic / multimedia designer, but because I am the only person here who deals with it, programming is something I am having to deal with more and more. I am learning fast but this one is causing me problems ;)

Many thanks

Paul aka 8bit Gamer


(This post was edited by 8bit Gamer on Dec 8, 2009, 1:05 AM)


Chris
Staff


Dec 8, 2009, 12:32 PM

Post #2 of 4 (5656 views)
Shortcut
Re: [8bit Gamer] Multiple image file names in one database field [In reply to] Can't Post

Hi Paul,

It seems like you've come a long way on your own! This can definitely be done with some PHP, try this:


Code
<?php foreach( preg_split('/,/', $upload['thumbUrlPath']) as $imageFilename ): ?> 
<img src="<?php echo $upload['realUrlPath']; echo $imageFilename; ?>" />
<?php endforeach ?>


I hope this helps! Best of luck!
Chris


Pixels & Beats
User

Dec 9, 2009, 7:42 AM

Post #3 of 4 (5639 views)
Shortcut
Re: [chris] Multiple image file names in one database field [In reply to] Can't Post

Brilliant! Got that working fine on the listings page. I had to modify it to stop after showing only 1 image by using a 'break' command. Not sure if it is the best way but it works lol!

I have tried to get the same technique working in the listing detail page. However, I keep getting all sorts of results apart from the one I want (which is to show all available images which can be clicked to show the full size image - standard stuff).

The results I keep getting are all images being shown multiple times, in multiple groups, which each group all sharing the same link. I can also get it so that the correct number of images shown and in the right order, but they all have the same url link to only one fullsize image. By moving the code around I get all sorts of other results, including all images being the same one repeated, but they all have different URLs (the opposite of the previous example! Gaaaaaaa lol)

Here is a copy of the code in one of it's forms. The other versions are just variations in order of this code:


Code
PHOTOS<br/> 
<b>Click photo to enlarge</b><br/><br/>

<?php foreach ($listing['uploads'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<?php foreach( preg_split('/,/', $upload['urlPath']) as $imageLargeFilename ): ?>
<?php foreach( preg_split('/,/', $upload['thumbUrlPath']) as $imageFilename ): ?>
<a href="<?php echo $upload['realUrlPath']; echo $imageLargeFilename; ?>">
<img src="<?php echo $upload['realUrlPath']; echo $imageFilename; ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="1" class="bikeimage" title="<?php echo $upload['info1'] ?>" alt="<?php echo $upload['info2'] ?>" /></a><br/><br/>
<?php echo $upload['info3'] ?>
<?php endforeach ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>


I have spent all day trying to get this to work but with no luck. I understand that the 'foreach' command runs until of the last 'array' (I think that's the right term), but getting it to do it all in the right way is driving me mad.

I am loving PHP though and think I will buy a book to learn more. Any recommendations?

Hope you can help with the above problem!

Many Thanks.

Paul


(This post was edited by 8bit Gamer on Dec 9, 2009, 8:07 AM)


Dave
Staff / Moderator


Dec 9, 2009, 11:14 AM

Post #4 of 4 (5636 views)
Shortcut
Re: [8bit Gamer] Multiple image file names in one database field [In reply to] Can't Post

Hi Paul,

Let's move this over to email since we're talking there already. But what I'd recommend first is storing the uploads in the format that CMSB expects so you don't have to parse the field values when displaying them.

It will make things _way_ easier.

I'll email you shortly.

Dave Edis - Senior Developer
interactivetools.com