liamloveslearning Posted May 16, 2011 Share Posted May 16, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/236586-get-value-out-of-database/ Share on other sites More sharing options...
requinix Posted May 16, 2011 Share Posted May 16, 2011 And where is this $user-offered-credit value coming from? Quote Link to comment https://forums.phpfreaks.com/topic/236586-get-value-out-of-database/#findComment-1216248 Share on other sites More sharing options...
liamloveslearning Posted May 16, 2011 Author Share Posted May 16, 2011 Sorry requinix, Theres no such thing but I presumed the correct solution would be to write a query which gets it, and thats what user-offered-credit would have been... Quote Link to comment https://forums.phpfreaks.com/topic/236586-get-value-out-of-database/#findComment-1216252 Share on other sites More sharing options...
liamloveslearning Posted May 16, 2011 Author Share Posted May 16, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/236586-get-value-out-of-database/#findComment-1216256 Share on other sites More sharing options...
requinix Posted May 16, 2011 Share Posted May 16, 2011 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.) Quote Link to comment https://forums.phpfreaks.com/topic/236586-get-value-out-of-database/#findComment-1216261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.