Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Random Images for Homepage.

  • 23-09-2012 10:53AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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,856 ✭✭✭✭Dave!


    Always glad to help


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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