|
-
Jan 7th, 2011, 02:23 AM
#1
Thread Starter
Fanatic Member
Display code randomly?
Hi guy's i've created a points script, which users can randomly earn points.
and then spend them on certain parts of my website. Im stuck on one part though and was wondering if anyone can help?
I need some sort of code that will display a submit button i've got - randomly..
Like so that, if a user, goes on a page, theres like a 25 % chance that it will display my submit button.
Thanks,
Jamie
-
Jan 7th, 2011, 09:01 AM
#2
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.
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Jan 7th, 2011, 02:15 PM
#3
Fanatic Member
Re: Display code randomly?
well 25% is simply make a random that will display 1 out of 4 times.
-
Jan 8th, 2011, 03:51 AM
#4
Thread Starter
Fanatic Member
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
-
Jan 8th, 2011, 04:05 AM
#5
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.
-
Jan 8th, 2011, 06:31 AM
#6
Thread Starter
Fanatic Member
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
-
Jan 8th, 2011, 06:41 AM
#7
Thread Starter
Fanatic Member
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
-
Jan 8th, 2011, 07:59 AM
#8
Thread Starter
Fanatic Member
Re: Display code randomly?
It's all cool now Done that, the codes now working! Thanks!
-
Jan 8th, 2011, 07:21 PM
#9
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.
-
Jan 8th, 2011, 10:00 PM
#10
Re: Display code randomly?
 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?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Jan 8th, 2011, 11:45 PM
#11
Re: Display code randomly?
 Originally Posted by Nightwalker83
What was the solution to that problem?
If you read the code he posted you should quickly find out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|