View Single Post
Old 05-23-2009, 02:47 AM   #15 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Back to what Sketch said, "if you're using so many if conditionals, there's gotta be a better way to do it" or something like that...
Yep, its a rule I personally stick too. If something turns out fabulously long winded, there is obviously a problem in the design. In those cases, a rethink and a re-factor are in order.

Quote:
1. ID
2. Thumb [0 if this is not the thumb, 1 if this is the thumb]
3. Picture [The picture url, left blank if Thumb == 0]
4. Picture Description [Will be what's in the <a title='' /> in the Thumb]
5. Bound To [The gallery the pictures are bound to, the ID of the thumb]
Do you need the thumb in the DB? I think we can leave PHP out of the processing of this (i.e. serving thumbs or full pictures and all the logic the accompanies it).

Easiest solution (bearing in mind, i quickly hack this together):

Have 2 pictures (I'm assuming you have a full and a thumb of each), name them <picturename>.gif and thumb_<picturename>.gif (or whatever).

Now all we do is prefix 'thumb' to the image to get the thumb:
PHP Code:
 <img src="thumb_<?php echo $row['image']?>.gif" />
And for the full size:
PHP Code:
 <img src="<?php echo $row['image']?>.gif" />
Now there is no need for more DB columns.


With a DB structure like this:
sql Code:
CREATE TABLE `portfolio` (
  `id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
  `image` VARCHAR(25)  NOT NULL,
  `description` VARCHAR(50)  NOT NULL,
  PRIMARY KEY (`id`)
)
ENGINE = MyISAM
CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Test data:
sql Code:
INSERT INTO `portfolio` VALUES (1,'test2.png','This is a test, test number two to be exact!'),(2,'test1.gif','This is a test, test number one to be exact!');

We could crudely output it thus:
PHP Code:
<div id="portfolio">
<h2>Portfolio</h2>
<?php while($row mysql_fetch_assoc($result)):?>
    <a href="<?php echo $row['image']?>">
        <img src="thumb_<?php echo $row['image']?>" />
    </a>
    <p>
        <?php echo $row['description']?>
    </p>
<?php endwhile;?>
</div>
That what you were after?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote