PDA

View Full Version : how to echo images in separate categories


nanny
01-20-2009, 07:00 AM
I have a table called photo with the categories id in it and a table categories.
I can echo the images in a repeat region and order by categories but when the page displays the categories need a space between them. I will explain what I mean:
Category 1 heading image image
image image image Category 2 image
image Category 3 image image image
image image

You can see how it displays - I want to know how to repeat the images in one category.

I know it will probably come to me eventually.......
Appreciate some help.

edbr
01-20-2009, 07:19 AM
not sure ive got this but heres what i think select by (example) $d
then in each category $d = Category1 ,$d = Category2 etc.

davidj
01-20-2009, 08:20 AM
code please

nanny
01-23-2009, 01:28 AM
Hi I have played around with INNER JOIN, RIGHT JOIN, LEFT JOIN and ORDER BY, and the result is always the same.

SELECT *
FROM categorytype RIGHT JOIN photo ON categorytype.categorytype = photo.categorytype



SELECT *
FROM photo
ORDER BY photo.categorytype

Because it will show all in the categories (categorytype is the primary id) but I want in the php repeat to show 5 thumbnail images in a row from each category e.g.
Adults
image image image image image
Kids
image image image image image
Production
image image image image image

where the image is has been repeated but also the the category is repeated from the database. Doing the ORDER BY:

<?php do { ?>
<?php echo $row_['categorytype']; ?>
<?php } ?>
<img src="images/gallery/thumbnail/<?php echo $row['thumbnail']; ?>">
<?php } while ($row = mysql_fetch_assoc($row)); ?>




It keeps repeating the one category until it has completed instead of showing a limit of 5 thumbnail the going onto the next category.

Hope that makes sense. Maybe it cannot be done.

davidj
01-23-2009, 05:50 AM
so every 5 thumbs you want a space

thumb thumb thumb thumb thumb
space
thumb thumb thumb thumb thumb
space
thumb thumb thumb thumb thumb
space

davidj
01-23-2009, 05:58 AM
also your example is invalid


<?php do { ?>

<?php echo $row_['categorytype']; ?>

<?php } ?> /*<<< this is terminating the DO above before the WHILE has been read*/

<img src="images/gallery/thumbnail/<?php echo $row['thumbnail']; ?>">

<?php } while ($row = mysql_fetch_assoc($row)); ?>


also your jumping in and out of PHP like a mad frog

nanny
01-30-2009, 02:52 AM
Didn't give full php code only a snippet of where I was using it - code works perfectly for me. I ended up using:

SELECT c.categorytype, c.name, COALESCE(p.photos,0) AS photos, p.thumb
FROM categorytype AS c LEFT OUTER JOIN ( SELECT categorytype, COUNT(*) AS photos, MIN(thumbnail) AS thumb FROM photo
GROUP BY categorytype ) AS p ON p.categorytype = c.categorytype

so I get a photo and category name and repeat with php.
It then links to the page that shows all for photo gallery.
Happy enough with that - will probably work better than my first creative action.

nanny
01-30-2009, 02:54 AM
Sorry forgot to say the termination of the do is to repeat category names only once in the photo gallery page instead of showing the name on every image that it shows.
Thanks for you help and pointing it out, makes me aware of what I am typing.