SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to apply a clickable URL to text links when they are an array

    I wonder how to apply a clickable URL to text links when they are an array of text and links. I don't know the right terminology to explain this, so I'll try to show you.

    End result: user will see a single thumbnail of a desktop wallpaper, and underneath will be the clickable wallpaper sizes for download. Number of sizes may range from 1-4. Click on the desired size to download the wallpaper.

    If I make it one thumbnail per wallpaper size, I could do that. But I want one thumbnail with all the different sizes below it. That's the trouble I'm having.

    Here are the two tables I've come up with. This assumes the user will click on an option in a drop-down box for a category, or click on a text link to show the latest wallpaper uploaded by DATE.

    PHP Code:
    CREATE TABLE `wpcategory` ( `IDINT UNSIGNED ZEROFILL NOT NULL  AUTO_INCREMENT ,
    `
    wpIDTINYTEXT  NOT NULL ,
    `
    DesignerVARCHAR(30)   NULL ,
    `
    ModelNameVARCHAR(30)   NOT NULL ,
    `
    CategoryCHAR(6)   NULL ,
    `
    ThumbVARCHAR(30)   NULL ,
    `
    DateDATE  NULL ,
    INDEX (`ID`) );
    INSERT INTO `wpcategory` (`ID`, `wpID`, `Designer`, `ModelName`, `Category`, `Thumb`, `Date`) VALUES  ('''10r5a''Steve''RC10R5''onroad''10r5a.150.jpg'NULL); 
    I created a one-to-many relationship bylinking the two tables with the following table's ID going into the previous table's wpID.

    PHP Code:
    CREATE TABLE `wpimages` ( 
    `
    IDTINYTEXT  NOT NULL ,
    `
    FilenameVARCHAR(30)   NOT NULL ,
    `
    SizeCHAR(11)   NOT NULL  );
    INSERT INTO `wpimages` (`ID`, `Filename`, `Size`) VALUES  ('10r5a''wp_10r5a_800.jpg''800 x 600');
    INSERT INTO `wpimages` (`ID`, `Filename`, `Size`) VALUES  ('10r5a''wp_10r5a_1024.jpg''1024 x 768');
    INSERT INTO `wpimages` (`ID`, `Filename`, `Size`) VALUES  ('10r5a''wp_10r5a_1280.jpg''1280 x 1024');
    INSERT INTO `wpimages` (`ID`, `Filename`, `Size`) VALUES  ('10r5a''wp_10r5a_1600.jpg''1600 x 900'); 
    This script successfully pulled all results when $wallpaper was replaced by "onroad" in phpMyAdmin:

    PHP Code:
    $wallpapersql mysql_query 
        
    ("SELECT wpcategory.ID, wpID, ModelName, Category, Thumb, Date, wpimages.ID, Filename, Size
        FROM wpcategory, wpimages
        WHERE (Category LIKE '
    $wallpaper') AND (wpcategory.wpID LIKE wpimages.ID)
        ORDER BY Date DESC
        "
    ); 
    On the actual page for displaying the above, I'm stuck. I know the following won't work because the proper relationships between the text link ("Size") is not linked to the filename ("Filename") to make the links clickable. There are several downloadable links associated with a single thumbnail.

    PHP Code:
    while ($wallpaper2 mysql_fetch_array($wallpapersql))

        
    $ID =  $wallpaper2['wpcategory.ID'];
        
    $ModelName =  $wallpaper2['ModelName'];
        
    $Thumb =  $wallpaper2['Thumb'];
        
    $Filename =  $wallpaper2['Filename'];
        
    $Size =  $wallpaper2['Size'];

        
    $ID htmlspecialchars($ID);
        
    $ModelName =  $htmlspecialchars['ModelName'];
        
    $Thumb =  $htmlspecialchars['Thumb'];
        
    $Filename =  $htmlspecialchars['Filename'];
        
    $Size =  $htmlspecialchars['Size'];

    echo 
    "<td>";
    echo 
    "<p style='text-align:center'><strong>$ModelName</strong><br />\n";
    echo 
    "<img src='http://aedownloads.com/downloads/wallpaper/".$Thumb."'><br /><a href='http://aedownloads.com/downloads/wallpaper/".Filename."'>$Size</a></p></td>\n"
    Is this information and description of my problem clear? Any direction you can share would be helpful. I striking out into new ground with this one.

    Regards,
    Steve

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT wc.wpID
         , wc.ModelName
         , wc.Category
         , wc.Thumb
         , wc.Date
         , wi.Filename
         , wi.Size
      FROM wpcategory wc
    INNER
      JOIN wpimages wi
        ON wi.ID = wc.wpID
     WHERE wc.Category = '$wallpaper'
    ORDER
        BY wc.Date DESC
    Obviously you'll need to make the html markup nicer, but hopefully this demonstrates the logic clearly.
    PHP Code:
    $thumbs = array();
    // make assoc array which makes groups of the diff sizes for each thumbnail id
    while ($row mysql_fetch_assoc($res)) {
        
    $thumbs[$row['wpID']][] = $row;
    }

    //print_r($thumbs);

    foreach ($thumbs as $thumb) {
        
    // because we used inner join, we will always have at least one size for thumbnail
        // so we can assume there will be an entry in array indice 0
        
    $ModelName $thumb[0]['ModelName'];
        
    $Thumb $thumb[0]['Thumb'];
        
    // etc...
        
        // show thumbnail
        
    printf('<img src="%s">'$Thumb);
        
        
    // now output the sizes we have
        
    foreach ($thumb as $size) {
            
    printf('<a href="%s">%s</a>'$size['Filename'], $size['Size']);
        }


  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks! You gave me a lot of information. I'll look up line by line to figure out what's happening.

    Steve H

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    What is happening here:

    PHP Code:
        printf('<img src="%s">'$Thumb); 
    I don't understand "%s." Is this MySQL's modulus operator? Is it PHP?

    I use echo"html goes here"; instead of printf. Are they synonymous?

    Thanks!

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Does your script replace my script, or is used in addition to it?

  6. #6
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    printf('<img src="%s">'$Thumb);
    // same as
    echo '<img src="' $Thumb '">'
    My code is incomplete. Like most posts here, it's meant as a demonstration of the logic needed.


Bookmarks

Posting Permissions

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