Copy link to clipboard
Copied
I've created an library that stores image names by ID and an image gallery table that stores the values of up to 15 images by image ID. The data looks like this:
ImageTable (id | name)
1 | one.jpg
2 | two.jpg
3 | three.jpg
4 | four.jpg
5 | five.jpg
6 | six.jpg
Gallery Table (id | slide1 | slide2 imageID ... and so on to slide15)
1 | 1 | 3 | 4 | null | null .... and so on to 15
1 | 2 | 5 | 6 | null | null .... and so on to 15
In this example the slide show 1(id1) would show one.jpg, three.jpg, and four.jpg
Slide show 2 would show two.jpg, five.jpg, and six.jpg.
If I pass a recordID (gallery.php?recordID=1) to the page I'm getting a perfect gallery recordset. Just one column comes in. I can't seem to figure out how to match that table row to the image table.
I think the problem is in the Query. I've tried dozens of loop and join queries but I can't seem to get anything to work I want to build a list of image names like this (html omitted):
if ($row_imgGalery['slide1'] == $row_imageTable['id']){
echo $row_imageTable['name']; }
if ($row_imgGalery['slide2'] == $row_imageTable['id']){
echo $row_imageTable['name']; }
if ($row_imgGalery['slide3'] == $row_imageTable['id']){
echo $row_imageTable['name']; }
// and so on
The closest I have come is to get the first row to return the right value. From there on I get either nothing or the images in order. I'm probably going about this all wrong. Any ideas would be appreciated.
Copy link to clipboard
Copied
>I think the problem is in the Query.
Rick, you are really making things hard on yourself
This is another case of a very poorly designed database. The gallery table should contain only 2 or 3 fields.
Gallery Table
==================
gallery_id image_id
1 1
1 3
1 4
2 2
2 5
2 6
Your design is not properly normalized. It has the potential of storing many null fields and is difficult to query from and a real pain if you ever need to increase the number of items stored.
Anytime you see a table that contains repeating columns (slide1, slide2, slide3 ...) or (user1, user2, user3...) you have to consider that this is not normalized properly.
Copy link to clipboard
Copied
I can see that I didn't explain myself very well. My Gallery table must have a unique ID for every gallery. 1 cant assign gallery 1 image 1 and then image 3 later one because the Gallery table populates the gallery page. I need a slot for each image just the same as a contact table needs a slot for first name, last name, address, etc.... The image slots are no different that that except that they all refer to image id's. If there's a way for a single record to call up 15 variables without having 15 columns I'd be interested in seeing it.
My image table will shortly contain about 2000 images. In a year it could contain 10,000. Each row in the image table contains the image ID, and a bunch of other data including descriptions, user ID for the person submitting the image and other things including metadata for the images. I've got the image upload and image data part of the system working perfectly. It's searchable by image type, user, date, photographer. It's beautiful. I can find any image in the library in seconds.
I've created a form to populate the Gallery table that uses a scrollable, searchable image gallery. You can select up to 15 images for each gallery. All that is stored is the gallery id (primary key) date (date the gallery was created) user id (id of the person creating the gallery) Gallery Name (self explanatory) Gallery Description (a descriptive paragraph for the gallery) and slots for up to 15 images. At the end of the table is an approval field. Set approval to no and the gallery pages no longer appear in the public menu structure but administrators can view and edit the page. I've used this technique for hundreds of different data sets from contact managers to blogs.
A simple Dreamweaver Master Detail page sets calls up the Gallery page by galleryID when a user clicks on a link. Originally I entered image names in the 15 available slots for images just to get things started. When using image names the gallery page works perfectly but there's no way to link to the other data.
The gallery page displays all images in a 3 column by 5 row layout. A slide show of the images can be played full screen. Having less than 15 images in a gallery is not a problem because if the column contains a null nothing is displayed on the page.
I can't be inserting Gallery ID's into the image records because one image may be used in multiple galleries. I don't want to insert all of the data from the Image table into the Gallery page because that's a bunch of redundant data. All that needs to happen is that the gallery slide 1 column needs to link to the same image id in the image table so I can retrieve and display the rest of the data. The only way that I can seem to make this work is to write up fifteen separate queries. There's got to be a simpler way to have gallery slide1 point to an image id and call up the fields and so on.
Because of a deadline I wrote 15 separate queries and the system works just fine. There's way more code than is necessary, but it works just fine. Every possible available image slot needed it's own query. If someone has an idea of how to simplify this please let me know. I'm going to go and soak my hands now. I've been typing code for 3 hours straight.
Here's my code that's working: (the html and other fields are omitted for clarity)
<li>
<?php
$slide1 = $row_pageRS['img1ID'];
$img1 = mysql_query("select * FROM imageLog WHERE id = $slide1");
if (mysql_num_rows($img1) > 0)
{ while ($row = mysql_fetch_assoc($img1))
echo $row['imageName']; }
?>
</li>
<li>
<?php
$slide2 = $row_pageRS['img2ID'];
$img2 = mysql_query("select * FROM imageLog WHERE id = $slide2");
if (mysql_num_rows($img2) > 0)
{ while ($row = mysql_fetch_assoc($img1))
echo $row['imageName']; }
?>
</li>
And so on until I get to slide 15.
Copy link to clipboard
Copied
Another question about the code I posted above. Should I release all 15 of those queries?
mysql_free_result($img1); and so on????
And if I put a free method after each query would I have to rename img1, img2 and so on? I'm not going to try it tonight, but it would make thins a lot simpler.
Copy link to clipboard
Copied
>And so on until I get to slide 15.
Extremely messy. Use a normalized table structure.
>My Gallery table must have a unique ID for every gallery.
Why? And if you insist, then create a gallery table that contains just gallery metadata and create another slide table that links the gallery to the slide.
>1 cant assign gallery 1 image 1 and then image 3 later
>one because the Gallery table populates the gallery page
I don't understand what you are saying here. Can you explain?
>If there's a way for a single record to call up 15 variables
>without having 15 columns I'd be interested in seeing it.
Using the tables I suggested, to select all images from gallery #1
SELECT ImageTable.name from ImageTable, Gallery
WHERE
Gallery.gallery_id = 1
Gallery.image_id = ImageTable.id
Copy link to clipboard
Copied
I see your point, but with 15 or less available slots available in the gallery (these are set by corporate mandate for allowable information) I'm going to stick with what's working. About 90% of the galleries that will be created will have all 15 slots filled. As conditions change images must be updated. IOW, if the Boiler in building G gets a new ID tag then Slide 3 in the galery for building G needs to be swapped out with the new image. My management system records who made the change, when they made it, what the last image for Slide 3 was, who created the gallery and a bunch of other stuff required for legal reasons.
Wouldn't your solution require15 insert new record button clicks to fill up a gallery? I don't know how to add more than one row to a table with one click.
My solution, while it took a while to code and has 9 lines of code for each image in the gallery takes one click to create a new gallery or 1 click to change every image in the gallery. The UI for the create and edit gallery page provides thumbnails for all images associated with a project and a simple java based click to populate the fields, a real time preview of all images in their proper position and then a single click to create the gallery. It's pretty idiot proof. The modLog runs in the background gathering user, workstation and time data to provide a complete audit trail for each image and each gallery. This also gives the company bean counters a single source for a spreadsheet with every gallery in the company on a single spreadsheet. They like that they can do that with a single button click.
If I were creating a gallery that was not so restrictive I'd probably go with your solution. I can see both advantages and disadvantages to your system.
Thanks again for all your help.
Copy link to clipboard
Copied
Rick, sorry for taking so long to respond - I've been traveling
>Wouldn't your solution require15 insert new record button clicks to fill up a gallery?
>I don't know how to add more than one row to a table with one click.
You would need to build a simple UI that provides multiple fields, and then use a loop to insert into multiple rows. It would probably take a few hours to build something that could be reused in different applications.
The problem I've seen with using with the tools/behaviors that DW provides is that developers create databases that match the tools' limited capabilities - and end up with bad database designs. So they wind up with a quick and simple solution for inserting data, but pull their hair out building workarounds and kludges to do queries and data analysis against these poor database designs. So, start with a good data model, and build your application around it.
Copy link to clipboard
Copied
Thanks for your reply... This model worked just fine for the particular project but as soon as I completed this project another similar one came up. I've worked out the multiple insert thing. We're now comparing data from 36 tables, looking for matches, and generating reports using a nicely normalized set of data. I can get most of what I need with a simple query. It's nice to design something from the ground up.