Jump to content

ghostcoder

Members
  • Posts

    26
  • Joined

  • Last visited

Everything posted by ghostcoder

  1. Ok, I'm using pushState, replaceState and popstate events along with Ajax to change content on a new project I'm working on. The basics are very simple and I've finally got it working well. However, I need to find a way to track and determine when a user is moving forward or back through the browser history, so that I can adjust the transitions properly. In my case, if someone goes back, I want the transition to be left to right, otherwise, right to left. I'm thinking the only way might be in a cookie. The system needs to remember history even if the person backs out of the site. ( as in, if you first load phpfreaks.com and the navigate to a site, move around a bit and then use the back button to go back to phpfreaks. Then, you may decide to click forward again to the site. Does anyone have any ideas on the easiest way to do this? Keeping some sort of array in a cookie, maybe?
  2. Ok, so I'm a fairly decent Javascript programmer and I've coded the majority of my functions from scratch along the way. However, I'm trying to get with the program here and separate as many event function calls from my HTML as possible. I'm also trying to decide if I should use Jquery or YUI or something, as opposed to writing everything myself. But that is a side question. One thing that in my studying so far is that I don't understand how advanced Event Delegation and Bubbling will work in some scenarios. For example, say I have a member search page and it displays 20 members at a time. Each member is in a DIV, but within that DIV, there is a small icon and if you hover over that icon, it triggers an onmouseover event. I currently have that event in line on the element. in short, it might looks something like this: <img src='/skin/default/magnify.gif' class='magnify' alt='mag' border='0' onmouseover="showfloat('/img/24386/9533.jpg','User name','United States, Southeast', 24386);" onmouseout='hidefloat();' /> So, the showfloat function has info that is easily assigned to it when generated by PHP. Img, username, location, and member id. Now, I suppose I could assign an event listener to every img with the class 'magnify'. Perhaps I could also create an ID tag for each of these images with the member ID. But how could I get all of the variables that I need to use in my showfloat function? I imagine I could do an AJAX call, but that wouldn't be nearly as fast as having all of that info preloaded in the page like I currently do. In another situation, I have a stream of posts, similar to a forum or to FB. Currently, I assign a lot of ID tags to DIVs using words along with an ID to identify which DIV I need for any particular javascript event. //I have a DIV id that looks like this: <div id='replyfield1234'></div> //then, I have a bunch of events in the HTML linked to the ID. Couple of examples onclick="doAddComment('addcomment', 1234); return false;" onblur='expandInput(this.id, 2, 117944);' //different ID for a reply In this situation, when there are so many events going on for so many DIVs and sub elements, how do I assign event listeners to everything and manage to keep track of the IDs? I can't assign the same ID more than once, and I still need to keep track of every event element relating to a particular ID. As above & in some cases, I might want to pass more info than just an ID to a function triggered by the event. Should I just wrap everything in a single parent labeled by an ID number? And then when events are triggered, I would somehow extract the ID of the parent in the Bubbling? I was looking at Twitter and I saw they have unique IDs in their html code, such as: data-tweet-id="2350143172699996##" data-item-id="2350143172699996##" Not sure how these work, or how you would access them from Javascript. If anyone has any feedback, I would appreciate it. I'm sure, like most programming things, once it really 'clicks' then I'll be off to the races.
  3. I don't see any delete query. Maybe you could post the code that handles the POST data and the deleting of the message.
  4. On a quick scan, I'd change your delete line from DELETE FROM writing WHERE a=$a to DELETE FROM writing WHERE a='$a' LIMIT 1 But I might not use $a as my variable name. Also, I'd escape it first. You can also echo what the value of your post data is and exit before you run the SQL. Then you can do a select on the table with the same value and see if it returns more than one row or not.
  5. Do you have a specific question? Asking about a 'messaging system' is quite vague.
  6. Have you checked out the Array page on php.net? http://php.net/manual/en/language.types.array.php Arrays can contain arrays, so you have true multidimensional arrays. You can also use an integer or a string for a key. print_r is handy for printing an array's contents to the browser, for example, so you can see what's going on with it at any time. Best thing to do is to start creating some arrays and playing with adding and accessing values to them. Hope this helps...
  7. Quick update. I'm still testing things, but since I added session_write_close(); to my php scripts being called via AJAX, I've not had a single browser freeze up! * knocks on wood * Thanks for the tip ajlisowski, and thanks for the other feedback as well. I'll report back here if things change.
  8. Thanks F1Fan, I'll check out the Firebug. I already use the web developer add on and it's awesome. Although it hasn't given me any hints here. Ajlisowski, thanks for the feeback. I have not been doing any session_write_close(); calls. I do a session_start() and that's about it. There is a place where I call session_destroy, but it has only been in certain cases. I will try session_write_close() and see what happens! I'll report back when I find out anything new... thanks again.
  9. I'd start by putting quotes around form values. name = 'form1' onlick='test();' etc... You can also put an alert above the var mytext line, just to make sure the function is being called when you click the button. alert('infunction');
  10. Start by adding a semi-colon after game() in your init function.
  11. Ok so I have an Ajax chat app that I've created. Works great. However, when running it locally on my Windows XP box with Apache installed, it freezes up over time, like in 30 minutes or something. It's very odd. I'm thinking it might be MySQL related, but it is definitely Apache related some of the time. The trick to getting it going again is switching Apache off and back on again. However, I'm getting tired of doing this over and over again. Any ideas ?
  12. Hello everyone, I have created a chat application and I'm really pretty happy with it. Only criticism so far seems to be that people don't always know when there is new chat. I have already coded in a few alerts to let the users know, but I think they still want more options. I have embedded a sound file that plays whenever a new chat comes in and the window isn't in focus. This works great. I also flash the top window title, works pretty good. This all happens on the popup window where the chat is running. Unfortunately, I don't have control over flashing the window tab in the bottom tray or anything. I guess people are used to Skype or Yahoo, which are actual applications. I'm just curious if anyone as any additional ideas or trick that I could employ to make it easier for my users to know if a new chat comes through. Thanks for reading.
  13. Where are the images coming from and how are they getting populated into your HTML output? A broken image in HTML will look the same in HTML as a regular image. You could use php or javascript to test the images. But I would consider using .htaccess Just depends on your specific needs.
  14. $_SERVER["REMOTE_ADDR"] Check this value and if you are not happy with it (empty or whatever), you can redirect them to another script.
  15. Jeffery, you cannot stop a php script and interact with it. Php is server side, so it will run the whole script before outputting the result to your browser. This is why you need to use a form to post the info back to the server. Use javascript and write a little function that takes your input and posts the value back to the server. You'll then run a php script to grab the posted variables and send your mail or do whatever else you want it to do. What I've done in the past is to have a form in the html with some hidden values. Like: <form method='post' name='myform' action='myscript.php'> <input type='hidden' name='mycustomfield' value='' /> </form> You can then take the variable in javascript and set that value before submitting the form. function formSubmit(form,info){ form.mycustomfield.value=info; form.submit(); } In php you grab the value of mycustomfield $_POST['mycustomfield'];
  16. Try a print_r($_FILES) before your loop to get a peek inside the array...
  17. Why can't you just post the input you get from javascript back to the server to process it via PHP? If you set it in a cookie, then you'll have to reload the php anyway to read the cookie data. AJAX would be the modern way to do it. I always thought it was much harder than it really is. Takes a little while to setup your personal system but it's fun once you get the hang of it. I've also seen an iframe technique to load another script without refreshing the current page. I think that's more of a hack approach and I would just try to use XMLHttpRequest if you MUST NOT refresh the page.
  18. I wouldn't store the article ID in the category table. I would store the cat_id in the articles table along with the article. You might also want to add a timestamp or datetime field to your comments table. Also not sure why you have an archives table. If you want to mark an article as archived, simply create a trigger field in the articles table. (or simply auto archive based on age of the article) You have the date in the articles table already, so you don't need an archives table.
  19. Hey guys, thanks for replying. I figured it out. My dyslexia must have been kicking in. normally I'll check the num_rows before I try to extract my result: if($getpoll->num_rows > 0){ but if the table doesn't exist in the actual query, then there is no result and that was ending the script. instead I just added: if($getpoll && $getpoll->num_rows > 0){ and also: if($getpoll){$getpoll->free_result();} at the end. This solved the problem. Feel free to delete this thread if you feel it's necessary. Sorry for starting the thread.
  20. SELECT *, (SELECT nmbrlogin FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword ) AS total_logins FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword; Extract the results. Check the $total_logins result for the number of existing logins. Then you can deny access and let the user know it's because they had x number of logins already.
  21. I wonder if it's possible to prevent my script from totally failing if it doesn't find a table in a query? I've tried to suppress the error with the @ but it still ends the script. Is it possible? If it is I'm totally missing something.
  22. Well, I already tried creating a string, with values separated by commas, and that doesn't work. Your functions return a single variable, and that will break a function that requires multiple variables. if there are three arguments, then the function should create something like return (function_exists($func) && $func($var1, $var2, $var3)); where $var1, etc are generated based on the func_check function $arg variable. The $var should be strings in this case. The dummy variables can be filler text.
  23. Hello. I'm trying to write a little function that checks for the existance of a function AND checks that it is returning true or false. Example follows: function returnMyText($name, $id){ return "My name is $name and my id is $id."; } function func_check($func, $arg){ //somehow I need to convert $arg (which is a number representing the number of arguments the function requires) into multple variables that I can dump into the $func() call below; return echo (function_exists($func) && $func()); } echo func_check('returnMyText', 2); Should run without errors and return True or False. I tried creating a string using a loop, but I didn't figure that would work. So, how can I create any number of dummy variables based on a number and pass them to a function, comma separated? I imagine this isn't too hard, but I don't know how to do it. Anyone care to chime in?
  24. Thanks again for your reply Daniel. That's good to know about the Globals. I've been programming PHP for a few years now and I've never bothered to use them. I've always used SESSION and local variables. Oh, as for the die(), I only use that when testing a script. Normally I use a custom function called sql_error(). In it I pass a note along with the actual error code. So it looks like this: $db->query("SELECT or other query'") or sql_error("my note about query",$db->error); Then in my function I'll deal with the error, logging it and emailing a note to myself about the failure. In some cases I'll also redirect a user to a custom error page. Having said that, I'll go read your blog post about the die(). Thanks again.
  25. Thank you very much Daniel. Your reply is much appreciated. Ok so, I'm glad I don't need to mess with the Singleton class. Your feedback on the Session variable makes sense, so I'll avoid that also. It would be cool if the PHP team had some special variable that would allow you to access specific database mysqli objects anywhere, without having to pass them around. Ok so, here's my plan. @ $db = new mysqli($DBhost, $DBuser, $DBpass, $DBname); if(mysqli_connect_error()){echo "Could not connect. Please try again later."; exit;} function myFunction($db){ // do my query $db->query("SELECT * FROM...") or die("Problem... ".$db->error); //do whatever here, return things if necessary } //call my stand alone function - pass the database object myFunction($db); //example of using it in a class class myClass { function anotherFunction(){ $this->data->query("SELECT * FROM.. or whatever"); //or error } } $simpleclass = &new myClass; $simpleclass->data = $db; $simpleclass->anotherFunction(); I'm using this method now and it works a treat. I'm not saying it's perfect, but it works. Is there any reason NOT to do it this way?
×
×
  • 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.