Jump to content

Recommended Posts

Hello everybody,

 

Very new to javascript so really stuck on this problem...

The website im currently building and is credit based and users specify how many credits there willing to give to other users providing they complete a task, this could be to visit a link they post, or visit their website. For example John could offer 10 credits to anybody who clicks his link through to his portfolio, If james was to click this link he would then receive Johns 10 credits, and john would have them deducted...

 

I have a table of users laid out as such...

 

ID  |    Username    |  Credits

1            Tom                3

2            john                32

3            jack                  52

 

At the moment i have a script which either +1 credits or +5 depending on the level of user, using the following script

 

 
    $(".getPoint").click(function()
    {        
       var theid = $(this).attr("id");
       var onlyID = theid.split("_");
       var onlyID = onlyID[1];
       
        $.ajax({            
          url: 'do.php',
          type: 'POST',          
          data: "userID=" + onlyID,
          success: function(data) {
              if(data != "success1" && data != "success5") {
                   $("#" + theid).text(data);  
              }else{
                
                  $("#thediv_" + onlyID).fadeOut("slow");
                  $('#creditsBalance').fadeOut("slow");
                  newbalance = parseInt($('#creditsBalance').text());
                  if(data != "success5") {                 
                    newbalance = newbalance+1;
                  }else{
                    newbalance = newbalance+5;
                  }
                  $('#creditsBalance').text(newbalance);
                  $('#creditsBalance').fadeIn("slow");
                  $("#" + theid).text("Done"); 
              }
          },
          beforeSend: function()
          {
                $("#" + theid).text("Working...");                  
          },
          error: function()
          {           
            $("#" + theid).text("Failed...Click to Retry");           
          }          
        });
    });
    

 

What im asking is how do I change the line...

newbalance = newbalance+1;

 

to say...

newbalance = newbalance+$user-offered-credit;

 

Thanks for any help and I hope this makes sense!

 

Link to comment
https://forums.phpfreaks.com/topic/236586-get-value-out-of-database/
Share on other sites

I've added a variable and assigned it a value

 

  var userofferedcredit = 1000;

 

which now works when I add the two

 newbalance = newbalance+userofferedcredit;

 

I just need to figure out how you assign the variable, a php value, could I use the document.write function to write the query?

 

Can you look up the value as PHP is constructing the page and insert it right into the JavaScript then?

Or does it depend on what the user does? (So the user submits whatever form, you look up the appropriate value, and do the updates.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.