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 all,
Vanilla are planning an update to the site on April 24th (next Wednesday). It is a major PHP8 update which is expected to boost performance across the site. The site will be down from 7pm and it is expected to take about an hour to complete. We appreciate your patience during the update.
Thanks all.

Random Images for Homepage.

Options
  • 23-09-2012 10:53am
    #1
    Registered Users Posts: 216 ✭✭


    Hi,

    I'm a complete noob when it comes to web development. It's not my field so bear with me. I'm making a personal website to showcase my portfolio and I want the homepage to randomly cycle between a set of about 30 images that I've set to be all the same size.

    Now I've put this code into my html, but the break; command doesn't seem to be working and so all the images load over each other. What am I doing wrong?
    <?php $rand = rand(1, 3);

    switch ($rand) {
    case '1':
    echo '<img src="images/Home_Loop/1.jpg" width="873" height="425" alt="image one"/>';
    break;

    case '2':
    echo '<img src="images/Home_Loop/2.jpg" width="873" height="425" alt="image two"/>';
    break;

    case '3':
    echo '<img src="images/Home_Loop/3.jpg" width="873" height="425" alt="image three"/>';
    break;


    default:
    echo '<img src="images/Home_Loop/1.jpg" width="873" height="425" alt="image one"/>';
    } ?>

    Thanks


Comments

  • Registered Users Posts: 216 ✭✭The Scratcher


    figured it out! my server doesn't have a PHP client. So I'm using javascript instead.

    This thread can be closed.


  • Closed Accounts Posts: 27,857 ✭✭✭✭Dave!


    Always glad to help


  • Registered Users Posts: 216 ✭✭The Scratcher


    Ok I've got another query!! I've got a CSS stylesheet that I "borrowed" from a site I like, I've tinkered with it a bit and all that and used a new font css, now I want to add a menu wrapper/container thingy that expands when you click on it, I've got java script for it but I can't seem to get the the wrapper/container to work in the CSS. Is it because I'm tinkering with an existing CSS?


    I'm in way over my head!!


  • Registered Users Posts: 1,082 ✭✭✭Feathers


    Hi,

    I'm a complete noob when it comes to web development. It's not my field so bear with me. I'm making a personal website to showcase my portfolio and I want the homepage to randomly cycle between a set of about 30 images that I've set to be all the same size.

    Now I've put this code into my html, but the break; command doesn't seem to be working and so all the images load over each other. What am I doing wrong?
    <?php $rand = rand(1, 3);

    switch ($rand) {
    case '1':
    echo '<img src="images/Home_Loop/1.jpg" width="873" height="425" alt="image one"/>';
    break;

    case '2':
    echo '<img src="images/Home_Loop/2.jpg" width="873" height="425" alt="image two"/>';
    break;

    case '3':
    echo '<img src="images/Home_Loop/3.jpg" width="873" height="425" alt="image three"/>';
    break;


    default:
    echo '<img src="images/Home_Loop/1.jpg" width="873" height="425" alt="image one"/>';
    } ?>


    Thanks

    I know you said you'd figured this out, but just to say that you don't need a switch statement here at all, you could just echo the random number in place:
    <img src="images/Home_Loop/<?php echo rand(1, 3); ?>.jpg"/>
    

    As for your CSS/JS question, the only real answer without seeing code is 'possibly' :)


  • Registered Users Posts: 216 ✭✭The Scratcher


    Thanks. I think I'm just in way over my head!! As I said I've absolutely no web development experience! I tried setting up a new grid with Bootstrap, but I just don't like how the page looks. I've decided to exclude the Javascript element for my menus and stick to the simpler version I had going and get the content up ASAP (There might be an issue with how this displays across browsers like IE but I don't care at this stage). I need to have it finished before friday so it's gonna have to be a country job! I only get about 2 hours to work on it per day too after work.


    I'll post a link here when I've it done for some feedback! :)


  • Advertisement
Advertisement