Jump to content

Howdy_McGee

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Howdy_McGee's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The problem with Javascript is that it won't keep track of the variable over time. As soon as the user refresher their page the number is reset to a static. I want to increment the number and also keep track of it as it gets bigger. I figured the easiest way to keep track of the variable would either be writing it to a file or database but because the user initiates the javascript, it gets called more than once, and written to the file more than once and therefore the number is incremented more than once (or so I'm thinking). I wasn't sure if there was a PHP function to prevent this or a better path to my solution :/
  2. I wan the number to increment by 1 every second no matter what. :S didn't realize I posted this 2 days ago sorry mods! Some suggestions were cron jobs or linux timestamps(?) and cron only goes by minute from my understanding not seconds. So that's kinda out the window.
  3. I am trying to duplicate this: http://www.usagain.com/ <--- On the left of their page they have a counter. I've literally tried everything I can think of but they have something going on in their PHP that I do not. My code is fairly straightforward: HTML/CSS/Javascript/AJAX <html> <head> <title>Counter</title> <script language="javascript" src="../jquery1.6.js"></script> <script type="text/javascript"> function addCommas(nStr) //http://www.mredkj.com/javascript/nfbasic.html -- Source { nStr += ''; x = nStr.split('.'); x1 = x[0]; x2 = x.length > 1 ? '.' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { x1 = x1.replace(rgx, '$1' + ',' + '$2'); } return x1 + x2; } function getNum() { $.post('test.php', function(data){ $('#counter').html(addCommas(data)); }) } setInterval(getNum, 1000); </script> <style type="text/css"> #counterContainer{color: #52504D;font-family:Verdana, Geneva, sans-serif;font-weight:bold;font-size:15px;position:relative;top:22px;} #counter{color: #1E7EC8; font-size: 25px;letter-spacing:1px;} </style> </head> <body onload="getNum()"> <div id="counterContainer"> <div id="counter"><!--Counter Goes Here, Do Not Disturb--></div> </div> </body> </html> And my PHP just reads the number in the file, updates the number, ehcos it back to AJAX, and updates the file. Here's the code: <?php $fp = fopen("staticNum.txt", "r+"); flock($fp, LOCK_EX); $num = fgets($fp, 11); $num = intval($num)+1; echo $num; fseek($fp, 0, SEEK_SET); fputs($fp, "$num"); flock($fp, LOCK_UN); fclose($fp); ?> The problem is if 2 people view the page at the same time, the number will increment by 2 instead of 1. If 3 people view it the number will increment by 3 and so on. How do I prevent this and keep it incrementing by 1 no matter what?
  4. So I am trying to create something similar to the counter on this page (left side toward top): http://www.usagain.com/ I literally been playing around with all kinds of different methods all day but no luck. I first thought I could just write to a file and pull it no problem, but don't want to put a read limit on it (since the number can get as big as needed) so I used filesize($myFile) which I'm assuming is what is keeping it from overriding the first long of my file. Instead it just keeps going and I have an incremented number that is just stacking next to all the other numbers. So that went out the window. I then though AJAX but then ran into the same problem above. Also learned that PHP variables have a scope like all languages ^.^ - - - Any suggestions on how to do this?
  5. :S umm... Creating a website backend from everything to logins through admin panel to editing website content and how it should be handled. All I know thus far is dealing with web forms, and making calculations via JSON + Ajax etc. I feel I have the knowledge I need it's just putting it all together is harder than I thought so I figured looking at a tutorial might help.
  6. So I'm pretty sure i know the basics of PHP and MYSQL but when I try to make a website backend I struggle. I was wondering if anyone knows of a tutorial the targets specifically creating a website backend / admin panel so I can get a generally idea of what is going on and what I should be doing.
  7. Ok, I have a PHP website that uses include to add in the header and footer. What is the wisest most efficient way to add in the separate keywords, descriptions and individual page stylesheets? Via database MYSQL or via multidimensional arrays?
  8. Wasn't quite sure where to post this but here it is. I was reading about arrays and it had briefly mentioned list() and each() but I wasn't quite sure what they did or where I would actually implement them in a real world situation. Can anyone go into more detail of what they actually do/why I would want to use these functions? I read more about them on php.net but it didn't really clear any of my confusions. Thanks!
  9. amazing! That gives me a much better understand on the POST array and how it's used. That works perfect i'm going to be playing around with this all week ^.^ thanks again!
  10. ohh ok thats great. So I need to make this kind of a 2 part process in order for this to work correct? Thanks for your help!
  11. Well all I am trying to do currently is have the user check a radio button. Each radio button has a different value assigned to it. When the user clicks on the radio button and submits the form I want the value of the radio button to be set to the value of the "amount" input box - that is where paypal is getting the final product price. I figured it would be easy to just set it with post but apparently it doesn't quite work like that.
  12. :S i'm fairly new @ PHP so im assuming there isn't really anything I can do here to get this to work? I would have to use something like javascript?
  13. So currently I am trying to create a form filled with options. Some of these options include radio buttons and drop down lists in which the user can select different variations of this 1 product. Then it will sum it all up and send 1 solid price to paypal. Well that is what I want it to do anyway. See Paypal gives me a simple API to work with in which it takes only 1 amount. My problem is that it will not accept any variables that are set via $_POST. I am trying to get the checked radio buttons value and add it to the value of "Amount" in this form - see below. <form action="https://www.paypal.com" method="post"> <?php echo "<input type='radio' name='group1' value='4.00'>Home"; echo "<input type='radio' name='group1' checked='false' value='10.00'>Work"; ?> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="test@test.com"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="item_name" value="Registration"> <input type="hidden" name="item_number" value="1011010102"> <?php echo "<input type='hidden' name='amount' value='$test'>" ?> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="button_subtype" value="services"> <input type="hidden" name="no_note" value="0"> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest"> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> <?php $test = $_POST['group1']; ?> **Note** using the above code will not work exactly. Anyone work with Paypal buttons before?
×
×
  • 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.