Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How do I rewirite a section of a page?

    Here's a link to the page I'm having trouble with: http://www.digitalzenmedia.com/products/thumbs.php

    Here's the header code used to set section and page id's. It's also used to create a path to the images used.
    Code:
    <?php
    
    DEFINE ('sectionId', 'products');	// sets Section ID
    DEFINE ('pageId', 'granites');		// sets Page ID
    
    ?>
    Here's the code that creates the content area:
    Code:
    <?php
    
    // Create HTML for text_area div and open thumbnails div
    echo "	<div id=\"text_area\">\n";
    echo "		<h2>Granites</h2\n>";
    echo "		<p>Select a color group:<br />\n";
    echo "		<form action=\"thumbs.php\" names=\"category\" method=\"post\" target=\"_self\">\n\n";
    echo "			<a href=\"#\">Green</a>\n";
    echo "			<a href=\"#\">Blue</a>\n";
    echo "			<input type=\"hidden\"  name=\"category\" value=\"green\" />\n";
    echo "			<p>&nbsp;</p>\n";
    echo "		</form>\n";
    echo "		<p>This is where the text regarding the various granite products will go.</p>\n";
    echo "	</div>\n\n";
    echo "<div id=\"thumbnails\">\n";
    
    //	Select category
    $category = 'green';
    
    // Create path to thumbnails
    $imgPath = '../img/' . sectionId . '/'. pageId .'/' . $category . '/';
    
    // Read all files that end with "_tn.jpg" in the images directory
    if ($dh = opendir($imgPath))
    {
    	$files = array();
    
    	while (($file = readdir($dh)) !== false)
    	{
    		if ((substr($file, strlen($file) - 7) == '_tn.jpg'))
    		{
    		   array_push($files, $file);
    		}
    	
    	}
    	closedir($dh);
    }
    
    // Sort the files by filename
    sort($files);
    
    // Display all thumbnails
    foreach ($files as $file)
    {
    	$name = (substr($file, 0, - 7));		// Strips off the "_tn.jpg from filename
    	$thumb = $imgPath . $file;				// Creates path to the thumbnail image
    	$large = $imgPath . $name . '.jpg';		// Creates path to full size image
    	
    	// Create one anchor tag for each thumbnail
    	echo "	<a href=\"$large\" name=\"$name\" class=\"thumb\"><img src=\"$thumb\" alt=\"$name\" name=\"$name\" width=\"42\" height=\"42\" /></a>\n";
    
    }
    
    // Close thumbnails div
    echo "</div>\n\n";
    
    ?>
    Here's the gist of it:
    First, the script writes out a div that contains the links to different colors of granite and opens the div that will hold the thumbnails.
    Next, it reads a directory and gathers all the thumbnails.
    Next, it creates a link for each image.
    Last, it close the thumbnails div.

    This all works fine to this point. Where I'm having a problem is, I'd like to use the links for each color of granite to simply change the content of the thumbnail div. I'm trying to avoid having to create a separate page for each different color. Here are some of things I've tried without success.

    Passing an argument through the href of the link back to the page. ie.:
    Code:
    <?php thumbs.php('green') ?>
    Creating a function to read hidden form input to set a default and using buttons to pass the color value.

    I've tried the code in the header, the body (this is where it is right now) and as an include.

    Here are my questions.
    1. Can I do this with PHP?
    2. If it can be done with PHP, how do I pass that value back to page?
    3. If it can't be done with PHP, how do combine JavaScript with PHP?
    4. Do I understand correctly that the PHP DOM functions only work on XML files?

    Any help would be appreciated. Thank you.
    Mike

  • #2
    New Coder
    Join Date
    May 2006
    Location
    California
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    make a div thats hidden, and when you click that color all others are hidden and only the one with that color shows. From what im understanding the part that you have like Green: Santa Cecilia is you want the name and image to change, you can do that using hidden divs for each image, or find a slideshow type of thing in flash where you could add images but it doesnt change automatically unless you click on a diff pic.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •