<script>
$(document).ready(function () {
var oMain = new CMain({
win_occurrence: 40, //WIN PERCENTAGE.SET A VALUE FROM 0 TO 100.
slot_cash: 200, //THIS IS THE CURRENT SLOT CASH AMOUNT. THE GAME CHECKS IF THERE IS AVAILABLE CASH FOR WINNINGS.
bonus_occurrence: 15, //SET BONUS OCCURRENCE PERCENTAGE IF PLAYER GET A WIN. SET A VALUE FROM 0 TO 100. (IF 100%, PLAYER GET A BONUS EVERYTIME THERE IS A WIN).
min_reel_loop: 1, //NUMBER OF REEL LOOPS BEFORE SLOT STOPS
reel_delay: 0, //NUMBER OF FRAMES TO DELAY THE REELS THAT START AFTER THE FIRST ONE
time_show_win: 2000, //DURATION IN MILLISECONDS OF THE WINNING COMBO SHOWING
time_show_all_wins: 2000, //DURATION IN MILLISECONDS OF ALL WINNING COMBO
money: <?php $kullanici_bilgileri->bakiye ?>, //STARING CREDIT FOR THE USER
min_bet: 0.05, //MINIMUM COIN FOR BET
max_bet: 0.5, //MAXIMUM COIN FOR BET
max_hold: 3, //MAXIMUM NUMBER OF POSSIBLE HOLD ON REELS
perc_win_prize_1: 50, //OCCURENCE PERCENTAGE FOR PRIZE 1 IN BONUS
perc_win_prize_2: 35, //OCCURENCE PERCENTAGE FOR PRIZE 2 IN BONUS
perc_win_prize_3: 15, //OCCURENCE PERCENTAGE FOR PRIZE 3 IN BONUS
num_symbol_bonus: 3, //NUMBER OF BONUS SYMBOLS (DEFAULT IS SYMBOL 9) THAT MUST BE SHOWN TO ACHIEVE THE BONUS PANEL
num_spin_ads_showing: 10 //NUMBER OF SPIN TO COMPLETE, BEFORE TRIGGERING AD SHOWING.
//// THIS FUNCTIONALITY IS ACTIVATED ONLY WITH CTL ARCADE PLUGIN.///////////////////////////
/////////////////// YOU CAN GET IT AT: /////////////////////////////////////////////////////////
// http://codecanyon.net/item/ctl-arcade-wordpress-plugin/13856421 ///////////
});
</script>
Hello, here is the code I wanna use PHP function in this JavaScript.
money: <?php $kullanici_bilgileri->bakiye ?>
I wrote it like this but that is not working for me.
To print any text in PHP you should use the echo or print function. So this line:
<?php $kullanici_bilgileri->bakiye ?>
Should be:
<?php echo $kullanici_bilgileri->bakiye; ?>
Edit: As far as I know is that you can't pass a PHP string without using the quotes in your javascript code otherwise you will get errors like
Uncaught SyntaxError: Unexpected identifier
So replace:
money: <?php $kullanici_bilgileri->bakiye ?>
With this:
money: '<?php echo $kullanici_bilgileri->bakiye; ?>',
As #Variable pointed out. if you would like to output a string, you will need to add quotes around it.
An alternative to have a proper typecast in JS is using json_encode, example:
{
...
money: <?php echo json_encode($kullanici_bilgileri->bakiye) ?>,
...
}
With this approach, you don't need to worry about forgetting the quotes.
Related
I am writing a randomized countdown that show number of products left in promotion alongside a timer. Number of products left is stored in the database, so all users see the same number. I am using simple php/ajax/javascript solution. My problem is with distributing the random sales so all fit within limited timer and are nicely distributed.
Here is code I have so far:
function start() {
$date= new DateTime();
$prod_left = getval("SELECT * FROM counter LIMIT 1");
if ( $prod_left == 20 ) {
$fp = fopen("../index.html", "r+");
while($buf = fgets($fp)){
if(preg_match("/<!--(.|\s)*?-->/", $buf)){
fputs($fp, '<script type="text/javascript">$(document).ready(function() {$(".countdown").circularCountdown({startDate:"' . $date->format('Y/m/d H:i:s') . '",endDate:"' . $date->modify("+5minutes")->format('Y/m/d H:i:s') . '",timeZone:+2});});</script></body></html>');
}
}
fclose($fp);
sleep(30);
while ($prod_left > 0) {
if (rand(0,4) > 2) {
$prod_left--;
sleep(rand(1,13));
updateval($prod_left);
}
}
} else {
echo 'Promocja w trakcie lub zakończona, zresetuj zegar, jeżeli chcesz rozpocząć ponownie';
}
exit;
}
My assumption here is: 50% of time decrease timer and wait on average 6.5 seconds, which should on average give me 260 seconds for full sale. Unfortunately its very unevenly distributed. My goal is to have the sale completed not later than 270seconds after start. Will you be able to help?
Implementation doesnt need to be in any particular programing language, im just looking for a clue/concept I can follow to achieve this.
What is the strangest, the $prod_left value not always goes to 0, on sime iterations it just sits at 3 or 5.
Please help!
Hello fellow Overflows,
So im in the middle of creating a toplist script, ready to launch to the public,
I'm stuck on one perticualr subject.
Displaying X amount of content from A database field.
<?php echo $server_data['description']; ?>
As you can see in this image below, That wouldn't be a good idea to display the full amount.
http://i.imgur.com/IhLs7L7.png
What do i need?
Instead of it displaying all of the database field, i just want it to display 150 characters of the field.
It is best to limit characters while you are selecting from database because it will improve performance a bit. You can limit characters on select with mysql LEFT() function.
Here is how to do it:
SELECT LEFT(description, 150), another_col FROM ......
Try this:
$string = substr($server_data['description'], 0, 150);
substr() will only return a certain amount of characters. If you want a certain amount of words then you could use the following:
<?php
function excerpt($content = '',$number_words = 125){
$content = strip_tags($content);
$contentWords = substr_count($content," ") + 1;
$words = explode(" ",$content,($number_words+1));
$excerpt = join(" ",$words);
return $excerpt;
}
echo excerpt($server_data['description'], 125);
I need to create a conversion chart from degrees Celsius, to degrees Fahrenheit. To do this, I need to use javascript to prompt the user for input for three things: starting temp in Celsius, ending, and the interval at which it will be displayed. Example:
start:100
end:10
interval:10
100 conv
90 conv
80 conv
70 conv
... conv
10 conv
Additionally, this data needs to be displayed in a table. Our instructor has not taught us how to dynamically change or create html or css elements, so I'm a little lost on how I will get the specific amount of cols and rows that ill need, and how I'll get the data in the right position before and after conversion.
Please help!
EDIT so I've been trying, and so far I have something. it looks like:
<script language = "javascript" type="text/javascript">
function prompts()
{
var startingTemp = prompt("Please enter the starting temperature.","Degrees Celsius");
var endingTemp = prompt("Please enter the ending tempurature.","Degrees Celsius");
var intervalTemp = prompt("What interval do you wish to display between the two?","Interval Number");
}
function table()
{
var myTable= "<table><tr><th>Celsius</th>";
myTable+= "<th>Farhenheit</th></tr>";
myTable+= "<tr><td>"+startingTemp"</td>";
myTable+= "<td>212</td></tr>";
myTable+= "</table>";
document.write(myTable);
}
prompts();
table();
</script>
however, the line where I have "+startingTemp" somehow messes it all up and won't print anything. With this included, the table doesn't print anymore and I'm also not being prompted when I reload the page. I'm just trying to get the value of startingTemp displayed there.
I found this question to be exactly the same problem I'm facing, but the answers suggested using objects for dynamic access. This might be well and good, but I'm looking for the exact simple answer on how to include a variable in a function's name.
I'm using ClockPick and dare not mess up the code, so I can't use objects or anything else. The problem is that with [ $("#clockpick"+x).clockpick ] the result isn't [ $("#clockpick0").clockpick ] but instead [ $("#clockpick"+x).clockpick ].
This all happens inside a PHP loop and it looks something like this:
var x = 0; (declared previously outside of the loop)
<script>
function doit()
{
$("#clockpick"+x).clockpick
({
starthour: 7,
endhour: 20
...
});
}
x++;
timepicker.php
<script>var times = 0;</script>
<?php
$goo = $_POST['goo'];
for ($foo = 0; $foo < $goo; $foo++)
{
?>
<script>
function clocker()
{
$("#clockpick"+times).clockpick
({
starthour: 7,
endhour: 20
});
} times++;
</script>
<?php
print "<input type='text' id='clockpick$foo' onclick='clocker()' />
?>
As mentioned, this works ok if I manually set "times" to a number, but as you can see, I don't know what number $goo has. In all, this is still a simplified demo from the actual page of 153 rows.
You are using a javascript variable to be incremented in a php loop.
The problem is that php will just write your javascript code as is, printing $("#clockpick"+times) at each iteration of the php loop.
To achieve what you want to do, you should use $foo instead of the useless javascript variable times like this
<?php
$goo = $_POST['goo'];
for ($foo = 0; $foo < $goo; $foo++)
{
?>
<script>
function clocker()
{
<?php
print "$('#clockpick$foo').clockpick"
?>
({
starthour: 7,
endhour: 20
});
}
</script>
<?php
print "<input type='text' id='clockpick$foo' onclick='clocker()' />"
}
?>
So far I have this which is comprised of snippets. I am not an expert in JavaScript by far so if anyone could help me achieve the following I would be very grateful and hopefully learn something new today :)
I want to achieve the following:
When a user types 1000000 into the input field the results shown are as follows,
Higher than $1 million
Lower than $1 million
Between $970 thousand and $1.3 million
Currently I can achieve the correct display of digits to prices but don't know how to add the word million, thousand, hundred to the end of the prices. Plus I'm not sure how to subtract 3% and add 3% to the price for the between price part.
Here is my code so far:
<input type="text" id="price" class="liveprice" value="<?php echo $myprice; ?>" >
<p>Higher than <span id="higher"><?php echo $myprice;?></span></p>
<p>Lower than <span id="lower"><?php echo $myprice;?></span></p>
<p>In between <span id="between"><?php echo $myprice;?></span></p>
<script type="text/javascript">
// make sure it adds commas and dots to price
$.fn.digits = function() {
return this.each(function() {
$(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
})
}
// update in real time
$("input.liveprice").keyup(function() {
var value = $(this).val();
$("#higher").text(value).digits();
$("#lower").text(value).digits();
$("#between").text(value).digits();
}).keyup();
</script>
If you want to know if it is higher than 1 million, divide the number by 1 million and then round the number using Math.floor(). If the answer is higher than zero then that is "how many million" you have. You can then insert the word million using something like (you'll need to add some stuff here):
var val = $('your input').val()/1000000;
if (Math.floor(val) > 0) {
$('your element with words').text( val + " million" );
}
Do the same for 1000 but just divide by 1000 instead of 1000000.