Hi, I am trying to design a dynamic website with a content management system and i was wondering what would be the best way to add content such as a photo gallery etc to the dynamic pages.

This is a general question but i will explain the problem i am having. I downloaded a script which allows me to add a photo gallery and i have included this at the top of the original page. I also have a php script which allows me to upload images, create a thumbnail and adds the name of both to a databse.

So far i have been adding the code to display the gallery to the database through the CMS and it displays ok apart from there is only one image and when i add a do while statement the other code remains but this statement is removed whenever i check it again. This is the code i have added:

<div class="ad-gallery">
    <div class="ad-image-wrapper" style="text-align: center;">
        <div class="ad-controls" style="text-align: center;">
            <div class="ad-nav">
                <div class="ad-thumbs">
                <ul class="ad-thumb-list">
                <?php do { ?>         //this line is removed
                <li style="text-align: center;"><a href="images/<?php echo $image['image']; ?>"> <img src="images/thumbs/thumb_<?php echo $image['image']; ?>" /> </a></li>
                <?php } while ($row_image = mysql_fetch_assoc($image)); ?>  // this line is removed

I'm sure there should be a better way then adding the code through the database but i have never built a website this way before and i cant seem to find any specific information explaining in more detail the correct way. Can anyone help me?

Recommended Answers

All 4 Replies

There are multiple ways to skin a cat.

You can use a database to link to the image files, but this is pretty pointless if the image files reside on the same server.

A better way would be to have a folder for images and use a for loop to link the files within the folder.

What i was trying to accomplish was that the user would access the image upload script, this would then add the image to the images folder whilst also creating a thumbnail and adding the file name to the database.

The code above then uses the do while statement to loop through all entries stored to add the images to the gallery. The code worked when i tested it on my computer but the loop disappears for some reason whenever i add it to the database (check comments in code).

how would i link it through using a for loop? this seems like an easier option but i thought that a database would be needed to store the names and amount of files to use in the loop.

Member Avatar

i am not sure about what do you want, but i found mystakes in your code.

<?php do { ?> //this line is removed
<li style="text-align: center;"><a href="images/<?php echo $image['image']; ?>"> <img src="images/thumbs/thumb_<?php echo $image['image']; ?>" /> </a></li>

It would be:

<?php do { ?> //this line is removed
<li style="text-align: center;"><a href="images/".<?php echo $image['image']; ?>.""><img src="images/thumbs/thumb_".<?php echo $image['image']; ?>.""/></a></li>

I will get them corrected thanks. I think i'm getting people lost off with my problem though so i will try and keep it more general and hopefully i can work it out from there.

If i have a dynamic website and i want to add content to a dynamic page such as a photo gallery or some php code or something what would be the best way to do it?

So far i have been adding code to the database and it doesn't seem to work properly unless its html. I think my problem is that the php code pulled from the database is not executing and therefore is just added as is. I'm sure this is not the correct way to do it but i'm not sure of any other way.

If anyone can explain a better way of doing it or point me to somewhere that can help i would appreciate it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.