Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

image gallery

  • 03-09-2008 3:45pm
    #1
    Registered Users, Registered Users 2 Posts: 788 ✭✭✭


    Hi

    I am making a simple image gallery. Users can upload the product images through a form. Each form submitted is recorded in database by an ID.
    In the gallery I call the products by ID. However users can submit up to 4 images in one form. These are called $id-1.jpg, $id-2.jpg, $id-3.jpg, $id-4.jpg. (For example if the id is 4, the images will be 4-1.jpg, 4-2.jpg, 4-3.jpg, etc)
    In my gallery i want it so the thumbnails will link to a page showing the main picture. I have this going through 'main.html' and changes by the form ID in database. But i dont know how to call each individual image (example: main.html?id=$id) in one form id. The database does not save any information about the images but is there another way i could do it without adding stuff to database?
    	<?php
    			echo "<tr>";
    		$result=mysql("$DBName","SELECT * FROM product WHERE cat_id = '3'");
    		while($row=mysql_fetch_row($result)) {
    				  $id=$row[0];
    
    	echo "<td><a href=\"main.html?id=".$id"\"><img src=\"../images/prod_images/$id-1.jpg\" alt=\"#\" /></a></td>";
    		echo "<td><a href=\"main.html?id=".$id"\"><img src=\"../images/prod_images/$id-2.jpg\" alt=\"#\" /></a></td>";
    		echo "<td><a href=\"main.html?id=".$id"\"><img src=\"../images/prod_images/$id-3.jpg\" alt=\"#\" /></a></td>";
    		echo "</tr><tr>";
    		echo "<td><a href=\"main.html?id=".$id"\"><img src=\"../images/prod_images/$id-4.jpg\" alt=\"#\" /></a><td>";
    		echo "</tr>";
    		}
    
    ?>
    


Comments

  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Hi meg,

    I think your naming convention is complicating matters a bit. What you could do instead is add a product id to the image database, and when you get to the product display page, you select all the images from the image database that have the corresponding product id. Then you simply loop through the results to display each image. In simpler terms:

    1. I'm browsing products, i click on one and am brought to the product display page
    2. I select all the necessary information from the products table based on the products id
    3. I then select all the images from the images table, based on the same product id
    4. I execute a loop that runs through the results from the query in step 3, displaying each image as it progresses.

    hope that helps.


  • Registered Users, Registered Users 2 Posts: 788 ✭✭✭sleepyescapade


    Thank you but what I mean is the above code is displaying thumbnails and I want to be able to click a thumbnail and be brought to view a bigger version of it on main.html. But i cant seem to find a way to link each individual image through the same id. Hope this makes sense!


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    megcork wrote: »
    Thank you but what I mean is the above code is displaying thumbnails and I want to be able to click a thumbnail and be brought to view a bigger version of it on main.html. But i cant seem to find a way to link each individual image through the same id. Hope this makes sense!
    right sorry. so when you talk about thumbnails and full size images, do you actually have two copies of the image or are you simply squashing one image for the thumbnails? can you not simply link to the full size image as you have done with the thumb? i.e. <img src=\"../images/prod_images/$id-2.jpg\" alt=\"#\" />


  • Registered Users, Registered Users 2 Posts: 788 ✭✭✭sleepyescapade


    Mirror wrote: »
    right sorry. so when you talk about thumbnails and full size images, do you actually have two copies of the image or are you simply squashing one image for the thumbnails? can you not simply link to the full size image as you have done with the thumb? i.e. <img src=\"../images/prod_images/$id-2.jpg\" alt=\"#\" />


    I have two copies of the image. I have an idea in my head but if it doesnt work i might be back ;)


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    a quick note first: you're better off using
    if($i &#37; 2 == 0)
    
    that way you can expand the number of thumbnails that can be displayed without editing that specific piece of code in the future.

    here's some old code that did pretty much what you're trying to do:

    [php]
    $sql="SELECT * FROM tbl_users INNER JOIN tbl_user_personal ON tbl_users.user_id = tbl_user_personal.user_id LIMIT 4";
    $result=mysql_query($sql) or die(mysql_error());
    $i=1;
    echo '<table><tr>';
    while($row=mysql_fetch_array($result)) {

    $profile_photo = get_profile_thumb($row);

    echo '<td><a href="profile.php?MemberID='.$row.'">'.$profile_photo.'</a></td>';

    if($i % 2 == 0) {

    echo '</tr><tr>';

    }

    }

    echo '</tr></table>';
    [/php]


  • Advertisement
Advertisement