Tear Me Apart [Banner Rotation]
Hey guys well this is me doing a tear me apart.
I havent been coding long but i got this to work Its pretty simple im not sure what can be changed, If anyone can tell me better ways of coding it and why there better that would help me alot. Sometimes a banner doesnt show up, Can someone tell me why this is aswell?
First off, it's not too bad. At least you're using switch logic and not if. That usually takes people more time to learn.
It's good practice not to name variables the same as a php function, ie: rand and $rand.
$rand = (rand()%4);
That line is going to return 4 numbers, 0-3. One thing you'll need to get used to is that a lot of things with programming start with 0 rather than 1. That's why you're getting a blank every once in a while because you have 0 being included in there and it's not being taken care of in the switch logic. So with that being said, change %4 to %3 and use numbers 0-2 rather than 1-3.
Kind of changing what I said before, but you could use just rand and not do that line you had before.
So do: rand(1,3)
This would return numbers 1-3 not 0-2 like I mentioned above.
You don't need that variable. Just put rand(1,3) in the switch statement.
Let me know if you need any furthre explaination! :)
yep you should listen to Ryans tips, he's an absolute genius at PHP
lol , all hail the almighty one :p
anywayz , keep at it and your learn php fast :D
That is great, i didnt know i could simplify it anymore cheers for that, This will help me out alot, and i wasnt to sure about the blank page but you cleaned that up as well cheers, Im Making a minature bank script at the moment, I will post that up here when i am done. Its simple but could be fun.
Argh, well, Ryan said everything I was gonna say plus more. To make it more interesting, you could use if commands so that when it's a certain time or a certain day, certain ads apear.
Slightly off-topic, but, anyone else reading this who's looking to rotate banners, phpadsnew.com is excellent. It's free and comprehensive.
one more suggestion,
you can just put all the iamge names in array and then it can spare you one more step, which is a big switch statement. like this
this will give you flexibility like,
in the first method, you can put any number of images in array
in second, just put images in directory and it'll automatically pick them up.
and ofcourse, using database is a totally different option
hope this helps
|All times are GMT. The time now is 01:17 AM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0