Jump to content

Get value out of database


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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.