Want to change JavaScipt to PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Want to change JavaScipt to PHP

Post by Vegan »

I have this ad display code, in JavaScript, wanted to make it PHP.....

Code: Select all

 
<script type="text/javascript">
// Display a tower ad
//var iNewHeight = left_col.scrollHeight;
var randomnumber=Math.floor(Math.random()*16); // chenge the muliiplier to the number of ads available
var ads = new Array();
ads[0] = '<a href="http://click.linksynergy.com/fs-bin/click?id=jaxflTaXP3Y&offerid=166833.10000242&subid=0&type=4"><img alt="Microsoft Store" src="http://ad.linksynergy.com/fs-bin/show?id=jaxflTaXP3Y&bids=166833.10000242&subid=0&type=4&gridnum=9"/></a>';
ads[1] = '<a href="http://click.linksynergy.com/fs-bin/click?id=jaxflTaXP3Y&offerid=166833.10000292&subid=0&type=4"><img alt="Microsoft Store" src="http://ad.linksynergy.com/fs-bin/show?id=jaxflTaXP3Y&bids=166833.10000292&subid=0&type=4&gridnum=9"/></a>';
// items removed for briefness
document.write(ads[randomnumber]);
document.write('<br />');
</script>
 
I wanted to run at server where I can focus on more functionality as time goes on.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Want to change JavaScipt to PHP

Post by requinix »

Code: Select all

$ads = array(
    // <a> link, <img> title, <img> source
    array(
        'http://click.linksynergy.com/fs-bin/click?id=jaxflTaXP3Y&offerid=166833.10000242&subid=0&type=4',
        'Microsoft Store',
        'http://ad.linksynergy.com/fs-bin/show?id=jaxflTaXP3Y&bids=166833.10000242&subid=0&type=4&gridnum=9'
    ),
    array(
        'http://click.linksynergy.com/fs-bin/click?id=jaxflTaXP3Y&offerid=166833.10000292&subid=0&type=4',
        'Microsoft Store',
        'http://ad.linksynergy.com/fs-bin/show?id=jaxflTaXP3Y&bids=166833.10000292&subid=0&type=4&gridnum=9'
    )
);
 
$ad = $ads[array_rand($ads)];
echo "<a href='{$ad[0]}'><img alt='{$ad[1]}' src='{$ad[2]}'/></a><br />";
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Want to change JavaScipt to PHP

Post by Vegan »

I assume if I add more rows to the list of advertisers, the code will be aware of the number of ads, that may change over time.

If the ads get out of hand, that is a future idea.

I have about 16 ads to display, more where they came from. I suggested 2 only as a suggestion of what I wanted to achieve.

Thanks for you code. I hope others like this thread.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Want to change JavaScipt to PHP

Post by requinix »

Vegan wrote:I assume if I add more rows to the list of advertisers, the code will be aware of the number of ads, that may change over time.
Right.
Vegan wrote:If the ads get out of hand, that is a future idea.
What does "get out of hand" mean?
Vegan wrote:I have about 16 ads to display, more where they came from. I suggested 2 only as a suggestion of what I wanted to achieve.
Just repeat the array(...) stuff.


What would be much better is if you put this all in a database. Much better. Highly recommended.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Want to change JavaScipt to PHP

Post by Vegan »

For now I am changing ads with the seasons so I am happy with a simple text file of ads for now.

I agree using a database is a good place to be, but not yet. I am still selecting a few more ads for the site.

Thanks again for the code, I am able to leverage it well.

As it stands now, I have 15 advertisements. I expect to have more by the end of the week posted.

I have to learn more about managing MySQL before I jump in.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply