php help stacking images

Discussion in 'PHP' started by coldclimber, Jan 6, 2007.

  1. #1
    I could do with a hand i am trying so stack my images on this page ( see my sig) in the shape of a pyramid so when someone ads a foot image the image will be display 1 on row 1, 2 on row 2, 3 on row 3 and so on until row 20 where they will just be laid next to each other as that is the maxi can show in a row. I would also like them to be shown randomly in no particular order.

    if any could help that would be great

    the code i have now is to display the images goes like this


    // Use the result
    while ($res = mysql_fetch_array($result)) {
    $resu[] = $res;
    }

    // Now we free up the result
    mysql_free_result($result);


    foreach ($resu AS $row) {
    echo "<a href='".$row['address']."' onMouseover=\"ddrivetip('".$row['description']."')\";
    onMouseout=\"hideddrivetip()\"target=\"_blank\"><img src='feet/".$row['colour']."".$row['leftright'].".jpg' border='0'/></a> ";
    }
     
    coldclimber, Jan 6, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    // $resu array contains all images loaded from mysql query
    // randomize order
    shuffle($resu);
    
    // per line starts at 1
    $perLine = 1;
    $onLine = 0;
    
    // go through array
    foreach ( $resu as $row ) {
        // do we need a new line?
        if ( $onLine == $perLine ) {
            echo '<br />';
            // reset counters
            $onLine = 0;
            $perLine = ( $perLine < 20 ) ? $perLine+1 : 20;
        }
        echo ShowImage($row);
        $onLine++
    }
    PHP:
    (untested)

    Does that help? I've used ShowImage() for readability - you can either create that function or put it back to echoing the HTML.
     
    rodney88, Jan 6, 2007 IP
  3. coldclimber

    coldclimber Peon

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    cheers that looks about right but what is that displaying just the basic results not the color of the foot and if it is left or right sorry to be a pain
     
    coldclimber, Jan 6, 2007 IP
  4. coldclimber

    coldclimber Peon

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ah i see it is loading the results from the database right. but i will need to add the mouse over effect to each image as this is part of the sites feature for the links:confused:
     
    coldclimber, Jan 6, 2007 IP
  5. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The whole thing then:
    
    // Use the result
    while ($res = mysql_fetch_array($result)) {
    $resu[] = $res;
    }
    
    // Now we free up the result
    mysql_free_result($result);
    
    // randomize order
    shuffle($resu);
    
    // per line starts at 1
    $perLine = 1;
    $onLine = 0;
    
    // HTML for showing each result
    function showImage($row) {
    return <<<EOF
    <a href="{$row['address']}" onMouseover="ddrivetip('{$row['description']}');"
    onMouseout="hideddrivetip()" target="_blank"><img src="feet/{$row['colour']}.{$row['leftright']}.jpg" border="0" /></a> 
    EOF;
    }
    
    // go through array
    foreach ( $resu as $row ) {
        // do we need a new line?
        if ( $onLine == $perLine ) {
            echo '<br />';
            // reset counters
            $onLine = 0;
            $perLine = ( $perLine < 20 ) ? $perLine+1 : 20;
        }
        echo showImage($row);
        $onLine++
    }
    
    PHP:
    Should work, might be the odd typo though.
     
    rodney88, Jan 6, 2007 IP
  6. coldclimber

    coldclimber Peon

    Messages:
    266
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    cheers thanks very much for that i am just going through it now i will let you know
     
    coldclimber, Jan 6, 2007 IP