Jump to content

Alex_

Members
  • Posts

    37
  • Joined

  • Last visited

Alex_'s Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. You could just send a GET request from your php script which gets the entire dom object from that page, and then use a dom-parser that can extract it for you. See example http://simplehtmldom.sourceforge.net/
  2. Don't understand what you're trying to achieve. There's an autocomplete on the input field, I get that. But you're not even adding the input fields to the <form> that you wanted to submit. So the data from the input fields will never reach whatever script the form is linked to. Not sure where you're trying to submit either, since there's no submit button.
  3. Doesn't look like you're adding the input fields to the form? If you are, print the output of $_GET in your php script. It won't be in $_POST considering you're using GET as the form method.
  4. Not entirely sure what you meant, but can't you just swap this line input = $("<input>").appendTo(div) with something like input = $("<input name='whatevername'>").appendTo(div) ?
  5. $update = "UPDATE password FROM $tbl_name WHERE pass='$newp'"; if($update) { echo " ".$row['username']." password has been reset! "; } else { die("Error"); } In short hand, you should, at the moment, always end up at the echo $row['username'] part. Which may seem right, but it's really not. Here's a small list of wrongs in that piece of code: - Your UPDATE query is wrong. Specify table first, then column (see below). It's also missing a "correct" WHERE clause - You never execute the Update query at all - You're asking the Script if the String $update has a real value, which it does, but it's a string, and therefor it's considered valid, so you get the message but the password is never updated, for several reasons. Here's how your Update query should look like: $updateQuery = 'UPDATE tableName SET pass = newPassword WHERE uniqueIdentifier = value'; $update = $db->execute($updateQuery); if($update) { ... } else { ... } Where you replace uniqueIdentifier with something like username/userid, and the value being either the username/userid. I see no uniqueidentifiers in your code there, but guessing it could be in session. So try that. Edit: no clue where this fontcolor came from, but oh well!
  6. Not sure I understood exactly what you meant, but I'm assuming a tag like this.. <a href="#">Link</a> You do not want it to process the code? If so, you could just wrap the current code inside the click eventhandler with an if-statement. if(this.href !== '#') { ... //Your code here } Or matching it for cases like href="#/link/here"> if(this.href.indexOf('#') === -1) { ...//Your code here } If I missunderstood, just let me know.
  7. That's the idea behind a switch statement. Should be no issues with that code you just wrote. However, because I'm picky, I want to point out that you are currently referencing your switch statement's keys with Strings. IE '65', '68'. Because browsers parse/react differently to javascript objects and keys/values, I'd like to make this suggestion: var keyCode = parseInt(e.keyCode); switch(keyCode) { case 65: ... break; case 68: ... break; } This way you can be sure it will work cross-browsers. I know some browsers tend to consider the keyCode as an integer, which makes sense. While others consider it a string. So in short, parsing the String to an Integer is the safer option here.
  8. The logical answer is that you'll need a way to determine when a user is active, or in "streaming terms": "Went live". You mentioned a Mysql Table where you currently retain currently Live streams. I'd say throw in a new column there that says when the Stream started. Doing so, you will be able to something similar to this: (Let's call the new column "UpdateTime", for example) Frontend var startTime; //Gets filled in startTimer() var streamsSelector = ''; //Selector for where you want the updated response function handleUpdatedStreamsResponse(response) { //Do whatever you want to do with the response here. //Preferably you should keep to using JSON responses from backend, but let's assume plain html for now.. $(streamsSelector).append(response); //The reason it's not completely overwriting the current html is because you'll only be returning the "Updated"/"New" streams from the backend. //This can of course be changed should you wish to handle it differently. //Also update the startTime startTime = moment().format('YYYY-MM-DD HH:mm:ss'); } function getUpdatedStreams() { $.get('streamUpdates.php?startTime=' + startTime, handleUpdatedStreamsResponse); } function startTimer() { startTime = moment().format('YYYY-MM-DD HH:mm:ss'); //Small tip: Always use momentjs. Lovely library! setInterval(getUpdatedStreams, 10000); //Fetch updated streams every 10 seconds ? } $(document).ready(startTimer); Backend <?php $db = new MyDbClass(...); $startTime = $_GET['starttime']; $rows = $db->query('SELECT * FROM mytable WHERE UpdateTime >= $startTime'); $response = ''; foreach($rows as $row) { $response .= buildHtmlBlock($row); //Some function that builds the html block for the new record } echo $response; This is very minimalistic and there's plenty of room for improvement, but I wrote it as simple as I could so that you could get the idea behind it.
  9. You should use callbacks on those three jQuery functions. Right now they're all executed at the same time, which may cause the effect you mentioned. var selector = 'div#stream'; $(selector).fadeOut('slow', function() { $(selector).load(location.href + ' #stream', function() { $(selector).fadeIn('slow'); )); }); Obviously that coding style isn't good practise, but it's to make it as simple as possible. Generally you would want to keep your callbacks as external functions and just reference them as the callback function. In any case, this means it will: - Fadeout - Load when Fadeout is complete - Fadein when Load is complete
  10. Assuming you're using jQuery just do something simple to get you started. function dataFetched(response) { //Parse response (whether its plaintext or JSON) //Add to the view } function getData() { $.get('getScores.php', dataFetched); } function startTimer() { setInterval(getData, 10000); //Every 10 secs } $(document).ready(startTimer); Assuming you followed Psycho's advice on moving the code out to a seperate file. There's obviously a lot of things to improve in the example above, it's just to get you started.
  11. Javascript is primarily used for that specific purpose, making a website dynamic/'alive', rather than a completely static 'dead' website. You could fairly easily implement a form of "timer" that changes the image every X seconds to a random image in any given list with just a few lines of code. Don't have to use jQuery, but it does make it easier. Not only to read, but also to write.
  12. What do you mean "keep repeating itself", is the fwrite function called more than once? Also not sure why you have the fwrite function in an if-statement prior to closing the file. The file pointer should always be closed, regardless of successfully writing or not.
  13. With just PHP alone you probably won't be able to pull it off, if I got your question right. You want to add an image to the rendered HTML Template using only HTML and PHP right? If so, I don't see how that would work. PHP isn't an event-driven language, and it's blocking. It'll render the template in your given if-else statement snippet above, and then it will consider itself done, and won't continue executing any more php-code. Maybe you can find luck in CSS, but that I doubt as well. I say as the first replier did, go with Javascript. It's easy and fast.
  14. Sounds more like a Redirect to me. And if that's what it really is, then I'm not entirely sure why you're trying to use the browser's history for it. Assuming your form submits to some php script that updates the formentioned data displayed on the previous-previous page (-2), you can simply redirect back to that page upon finishing the update of data in the script. Or am I assuming wrong?
  15. Yeah IP and unique Session ID is what I was trying, like trying to prevent further requests until the first one is finished, but attempting to limit it in any way ended up not working, because then i'd be stopping the "most recent" request object which in turn means the user gets no response at all.
×
×
  • 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.