-
Posts
5,717 -
Joined
-
Last visited
-
Days Won
6
Everything posted by Adam
-
Better to use an interval in this case: var counter; var count = 1; function do_count() { document.getElementById('counter').innerHTML = count++; } window.onload = function() { counter = setInterval('do_count()', 1000); }
-
I think what err.. adhbvklwqdbviabjiawdnbij is after, is the text appearing dynamically on the page - i.e. JavaScript. It's very simple to do. Run this and let us know if it's what you're after... <div id="output"></div> <script type="text/javascript"> var i = 0; var timer = setInterval(function() { document.getElementById('output').innerHTML += 'The number is ' + ++i + '<br>'; if (i == 5) { clearInterval(timer); } }, 3000); </script>
-
First I would ensure all the paths are correct to your scripts, stylesheets and images. A quick way to do this is just view the source and click the path link for each (generally browsers convert them to links these days).
-
You can do this easily with explode (and rtrim() to remove the trialling slash): list($host, $port) = explode(':', rtrim($string, '/')); Edit Didn't spot the "without http://" comment, use this instead: $string = str_replace('http://', '', $string); $string = rtrim($string, '/'); list($host, $port) = explode(':', $string);
-
No problem, and it turns out you can. I didn't realise this before, which is why I suggested you're likely talking about classes due to the similar syntax. Once you've called the parent function you're also able to call the child function directly: function foo() { function bar() { echo 'baz'; } } foo(); bar(); // echoes "baz" In response to your original question though, you don't need to define a function within a function to call it. Functions can call any functions that have been defined. Recursion is a function calling itself. Doesn't neccesarily need to return anything or call any additional functions, just call itself.
-
I would assign the event to the submit, but not onclick of the submit button. Assign it to the actual form onsubmit="..." event, otherwise the user could press enter to submit the form and it wouldn't be validated. It's then up to you if you want to add further validation to individual inputs as they enter text, but I would personally use a timer to delay the validation by about 2-3 seconds after they press a key, and reset the timer every time the event is called. You'd also want to bind it to the onblur event in this case. It just makes the process feel a lot smoother, not big red error messages popping up after you've entered the first character.
-
delete Dublicates from very large two dimensional array
Adam replied to pilixonis's topic in PHP Coding Help
That's because PHP isn't built for handling such large data sets. You're better off doing this on the database side. You can remove duplicates like so (imagining your table is called "contacts"): delete from contacts c1 using contacts c1, contacts c2 where c1.id != c2.id and c1.phone = c2.phone -
system accepts a second parameter to store the response from the server. Instead of echoing it, store the result and use that variable in your comparison. $5 is not a valid custom variable name by the way, as it starts with a number.
-
You can't have a function within a function. You're most likely thinking of classes: class Foo { function bar() { // ... } } These are a very different concept, far beyond the scope of this post. If you would like to learn more though there's plenty of information in the manual, and an Object Orientated PHP Tutorial on the main site here. Recursion is something completely different, it's basically a function calling itself. For example a function that can take either an array or string as an argument, but if it's an array calls itself with each string item in the array. Very simple example: function recursion($arg) { if (is_array($arg)) { foreach ($arg as $str) { recursion($str); } } if (is_string($arg)) { echo $arg . "\n"; } } recursion(array('foo', 'bar')); recursion('baz');
-
I think I go a $page_contents problem, please help
Adam replied to CraftHell's topic in PHP Coding Help
You would be right, and that's exactly your problem. HTTP requests are relatively slow, and making (what sounds like you're trying to) thousands at a time is a ridiculous load on both your server and theirs. This problem is generally overcome by "scraping" their website, page by page with a courteous delay in between, indexing the data in your own database and then querying that for the details later. Think search engines. This is of course assuming you're not violating their terms of use, and they may still block you. I'm surprised they haven't already if you're firing off even 10 requests at once - probably just a matter of time till they notice to be honest. -
Read this ^ .. You're basically updating the data after you've already displayed it, which is obviously not going to show the updated data until the next request.
-
Can anyone help me make this more efficient? (More of an SQL question)
Adam replied to Jezw's topic in PHP Coding Help
The problem with your method is that you're assuming the next image will always be the ID + or - 1. What if the user adds an image to an older gallery? Your system won't be able to handle it. Instead try to think of it more like pagination, but only showing a single result per page. You get a count of how many images are in the gallery, and then use a parameter to pass the "page" (or better worded as "image") offset in the gallery. Also you can save yourself the sub-query by passing the gallery ID within the URL. So first, get a count of how many images are in the gallery into a variable ($max_images let's say). Then get the current page/image number from the URL (defaulting to 1 if none has been passed - also remember to subtract 1 from this value, as the LIMIT clause is 0-indexed). Then using that return the image data, limited to the current page/image number (i.e. LIMIT $image, 1), and ordered by the image ID. From this point a simple condition on the current page/image number against 0 or $max_images should tell you whether you need a previous and next link respectively. There's a tutorial on the main site covering Basic Pagination that would probably help you. -
With all due respect "runeveryday", the PHP manual explains many of your answers. So would Google on the 'why port 43' question.
-
That was not my suggestion? I posted: {$people->getShow()|escape} {$people->getName()|escape} Use that wherever you want the values to be shown; don't assign them to a variable! I would always hesitate to assign a variable within SMARTY, there's generally always a better way.
-
After testing this it seems I made a few mistakes in my last posts. The status property returns a numeric value, 200 on success, and the statusText property returns "success". You also need to set the 'async' option to false, otherwise the return statement will be called before the request has finished. So the code would be: var request = $.ajax({ async: false, //... }); return (request.status != 200);
-
Or in a more obvious syntax: if (request.status == 'success') { return false; }
-
You can store the AJAX object within a variable, and determine what to return based on the status: var request = $.ajax({ [...] }); return (request.status != 'success');
-
This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=342898.0
-
That's because you're within an additional function there: You're only returning from that.
-
You're asking too much at once. The best way you'll learn from this is through trying it yourself first. Ask for help if you get stuck, or ask for others peoples' opinions on what you've done so far. If you want a point in the right direction please re-word your post, so that we have a specific direction to point you in.
-
It's SMARTY I believe. The templates are compiled into pure PHP templates, that are then re-used on subsequent requests. I'm not sure why there's angle brackets at each side of an assignment though? I'll add as well, there's no need to really assign the value to a variable here. @kvnirvana why not just display them separately..? {$people->getShow()|escape} {$people->getName()|escape}
-
I'm a little confused by why a toggle would animate it in the opposite direction? You need to literally include an animation that will take it the opposite direction.
-
There is an "onClose" event you could utilize for that. http://jqueryui.com/demos/datepicker/ > Events > onClose.
-
http://www.pc-library.com/ports/tcp-udp-port/43/ You're sending data to that server, on port 43, via a socket connection. The fputs function simply handles writing data to that stream; which is the $conn resource. The server is listening for the request on that server, and once you write to it, it writes back a response which is collected using fgets.