Page 1 of 1

Want to change JavaScipt to PHP

Posted: Sun Nov 08, 2009 6:22 pm
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.

Re: Want to change JavaScipt to PHP

Posted: Sun Nov 08, 2009 6:41 pm
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 />";

Re: Want to change JavaScipt to PHP

Posted: Sun Nov 08, 2009 8:35 pm
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.

Re: Want to change JavaScipt to PHP

Posted: Sun Nov 08, 2009 9:23 pm
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.

Re: Want to change JavaScipt to PHP

Posted: Sun Nov 08, 2009 11:21 pm
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.