Re: Display code randomly?
Not sure about how to make sure its a 25% chance and I don't know much about PHP, but I think you could simply make a random between 4 different values and if it happens to be the right one then display the button.
All you need is to use rand and then an if statement to check which value was selected.
I think that would be a good start.
Re: Display code randomly?
well 25% is simply make a random that will display 1 out of 4 times.
Re: Display code randomly?
Hiya, Thanks for the replys!
By anychance, do you know what code it would be to use, for the rand function to do so?
Thanks,
Jamie
Re: Display code randomly?
Something like this should work:
PHP Code:
$randint = rand(1,4);
if ($randint == 4) {
// button code here
}
But you may want to keep a log of who it displays too. For example, you may only want them to see this button once ever, or once a week/day/hour etc. Other wise, every page refresh, they will have 1/4th chance of seeing it.
Re: Display code randomly?
Thanks dclamp!
Quick question what would i edit, To make it so the user would only see it once, and never again?
Thanks,
Jamie
Re: Display code randomly?
Code:
<?php
$randint = rand(1,4);
if ($randint == 4) {
// button code here
<form action="http://vitalradio.co.uk/scripts/points/100.php" method="post" name="myform" id="myform">
<input name="doSave" type="submit" id="doSave" value="Redeem Points">
}
?>
Im using the code above - But i keep getting a syntax error, Unexpected T_VARIABLE .
Any idea why?
Thanks :)
Re: Display code randomly?
It's all cool now ;) Done that, the codes now working! Thanks!
Re: Display code randomly?
If you only wanted them to see it once, you would either need to use a database and log some sort of user id. Alternatively you could use cookies but cookies can be manipulated or deleted in order to gain more points.
Re: Display code randomly?
Quote:
Originally Posted by
JamieWarren09
[CODE]
Im using the code above - But i keep getting a syntax error, Unexpected T_VARIABLE .
Any idea why?
What was the solution to that problem?
Re: Display code randomly?
Quote:
Originally Posted by
Nightwalker83
What was the solution to that problem?
If you read the code he posted you should quickly find out.