1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Using PHP to display a random product of your choice from your AmazonAssociate acount

Discussion in 'PHP' started by mitchandre, Jan 3, 2006.

  1. #1
    All of us wish to customize our Amazon Associate Accounts as much as possible, the following code allows you to display a random product on your home page from a collection of products you have already approved. The code assumes you have a working knowledge of html and only struggle with your php code. For best results place code into a table or frame of choice. You can see the code in action at http://www.chemicalforums.com

    <html>
    <center>
    <?php
    $random_integer = rand(0,2);
    switch ($random_integer){
    
    case 0:
    $link = "http://www.amazon.com/exec/obidos/ASIN/1550225200/thechemicalfo-20?creative=327641&camp=14573&link_code=as1";
    $title = "That's the Way the Cookie Crumbles";
    $image = "http://rcm-images.amazon.com/images/P/1550225200.01._SCTZZZZZZZ_.jpg";
    break;
    case 1:
    $link = "http://www.amazon.com/exec/obidos/ASIN/1550226215/thechemicalfo-20?creative=327641&camp=14573&adid=1XKK9N3R1F3JGJNAW1PP&link_code=as1";
    $title = "The Fly in the Ointment";
    $image = "http://rcm-images.amazon.com/images/P/1550226215.01._SCTZZZZZZZ_.jpg";
    break;
    case 2:
    $link = "http://www.amazon.com/exec/obidos/ASIN/0060936770/thechemicalfo-20?creative=327641&camp=14573&adid=0P6STKS2KBJ5AEYF625J&link_code=as1";
    $title = "The Cartoon Guide to Chemistry";
    $image = "http://rcm-images.amazon.com/images/P/0060936770.01._SCTZZZZZZZ_.jpg";
    break;
    }
    echo '<a href="', $link, '">', $title, "<br>", '<img src="', $image, "\"><br><center><a href=\"http://www.chemicalforums.com\">Chemistry Forum</a></center>";
    ?>
    </center>
    </html>
    PHP:
    Notes on Editing Code: From the above code you can see how I've listed 3 different products and also have a random number generator from 0->2. Thus if you desire to add more products you simply need to increase the 2 to your desire and add more cases to your desire. Also, I have it so a discrete link to my website is also included, feel free to add another link to my website using the above format and removing the link in the code if it suits your needs better. But, I do ask that my link show up somewhere on the same page as the code you use. But, like most things on the net this is not enforceable.
     
    mitchandre, Jan 3, 2006 IP