Thread Contributor: dragonhunt3rhelp needed.
#1
ayo there.. currently got stuck , coding a website that allows you to gamble, there are 10-300 slots in each giveaway, and for example you need 1$ for each slot to purchase, each 1$ is 1 slot out of 150 for example. the problem is that whenever they click on slot-number (to purchase) they buy it, but site doesn't refresh automatically to renew taken slots. you have to do it manually by pressing reload button to renew.. i was wondering.. what should i do to make it renew taken slots automatically? Peace.

@ubersaki you might know dis.. :D
#2
Regardless of where you're storing the taken slots, i.e. database? a text file? just in the code?

I think the most standard resolution for something like this is to use jQuery's AJAX library.

You can communicate with your web server & database, modify/retrieve information, and get the data back and display it
without having to reload the page.

You can create a time-based function that ticks maybe every 1.5k ms, and that can then read and display the slots.

If I understood your question properly, then this should work.

You may have some issues with dynamic-DOM depending on how you handle the callback data, but I should be able to
help you with that.

Good luck.
Reply
#3
@Baredee here's the code..

Code:
<p>Choose your slot number
              or:</p>
              <button class="random_place" onclick="buy(0,<?php echo $_ITEM['id'];?>,<?php echo $_ITEM['price_p'];?>)">Randomly choose slot number</button>
              <?php
              }
              ?>

and here's what i exactly want : if someone purchases slot #37 for example, site would reload and display that slot #37 is taken by %user%, but with this code, nothing changes until you don't reload your webpage manually (refresh) do i have to add something like location.reload(); ?
Reply
#4
(08-21-2016, 10:08 AM)dragonhunt3r Wrote: @Baredee here's the code..

Code:
<p>Choose your slot number
             or:</p>
 <button class="random_place" onclick="buy(0,<?php echo $_ITEM['id'];?>,<?php echo $_ITEM['price_p'];?>)">Randomly choose slot number</button>
 <?php
 }
 ?>

and here's what i exactly want : if someone purchases slot #37 for example, site would reload and display that slot #37 is taken by %user%, but with this code, nothing changes until you don't reload your webpage manually (refresh)  do i have to add something like location.reload(); ?

Show me the 'buy' function
Reply
#5
@Baredee

http://pastebin.com/W1MSJ18z here's full page, take a look. ty.
Reply
#6
(08-21-2016, 10:45 AM)dragonhunt3r Wrote: @Baredee

http://pastebin.com/W1MSJ18z here's full page, take a look. ty.

I don't have much agility with the machine I'm currently using, as I'm on holiday - but I understand the gist of it.

I'd just like to say that your app would look beautiful in Node, and it would be easier to create (by the virtue of AJS)

As for this, I still cannot see the definition of your 'buy' function, and you have other .php includes and variables.

But generally, this is how you would go about doing it:


Code:
var buy = function(foo,bar){

 // we send a request to the .php that handles it, using ajax
 
 $.ajax({
    type: 'POST',
    url: 'your_php_file.php',
    data: 'var1=' + foo + "&var2=" + bar,
    success: function(data){
   
    /*
      if you format & make your .php file 'echo' the returned data, it will get sent into this function as a callback named: 'data'
      in other words, all your info is in 'data', right now - so do what you need to do with it here
   */

    // Next, load it into the page
   $("some_element").html(data);    


    }

});

};

Not sure how simple it is but it's just one function with one AJAX request in it.

Perhaps reading the docs of AJAX and JQuery DOM on W3S will help.
Reply
#7
Maybe consider using Laravel for this. You can easly make requests back and forth and interact with the database really easy.
But however I need your full source and better explaination to help you out here since im such bad in english and I do not fully understand your goal!
Reply
#8
Heres a couple things I noticed....

first, you use $_ITEM['place_n']==0 ... you need to use === for absolute. both = and == can give errors.

setcookie("ref", $_REQUEST['r'], $time, "/"); could lead to potential sql via cookies.

mysql_real_escape_string(clear_string($_REQUEST['id']))."'")); ... why use request instead of get/post? also, you could probably sanitize most of the inputs before using them so u dont have to escape string and clear string on so many vars.

you should also, at minimum, upgrade the code to mysqli usage instead of the old mysql
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)