Jump to content
MakeWebGames

Floydian

Members
  • Posts

    900
  • Joined

  • Last visited

    Never

Everything posted by Floydian

  1. Re: Basic Ajax is easy I'm a bit curious. I've seen games that use ajax, and games that don't. I know for a fact that mccodes doesn't come with anything that uses ajax by default. Personally, I think ajax can be used to greatly improve the usability and user friendliness of a web page. One of the big benefits of ajax over some other technologies like say, java, flash, and others is that ajax is essentially javascript. This means that every major browser supports ajax out of the box. It costs nothing to get started developing an ajax application. Whereas buying a flash editor can be hella expensive. There are free java editors out there, and one good one comes with the eclipse platform. However, java is considerably harder than ajax to implement, and again, requires that your users have downloaded java to their computers. So, my curiosity is this: does ajax seem like it's something that is too difficult to implement? Do people prefer to just have static web pages? Or perhaps, maybe understanding where ajax can be of use is the problem? Or perhaps there is no problem, and everyone understands and is using ajax already ^__^ Just wondering. I've seen many an ajax tutorial out there, and while they explain how to make an ajax request, I haven't seen one that really provides a usable example. I was hoping that my example would be something people could use right away with just a little bit of modification. Mainly the html file would have to have the header and footer content you want, and the php file would have to contain the dynamic content you wish to display.
  2. Floydian

    Adobe CS3

    Re: Adobe CS3 Excellent point Nyna, I use the GIMP for all of my image editing. That program has a nice following, but doesn't get as much credit for being as good as it is compared to photoshop IMHO. Of course those that have used it and photoshop know that in the hands of a skilled user, just about anything you can do in photoshop can be done in the GIMP.
  3. Re: Best way to write this? Awesome! :D :mrgreen:
  4. Re: Best way to write this? I think any speed difference would be negligible. Okay, I've given my answer to your question, now for unsolicited advice lol Your assumption that calling a "method" is the essentially the same as including a file with the code in that method is in error. Yes, it's a minor technical thing, but it's something worth thinking about as this will lead to a proper understanding of when and why to use one or the other. First, the thing you refer to "$h" is an object. This object is defined in the header.php file. The name of the class is "Header". When you use a class, you store it in a variable whose type is object. This is opposed to having a variable whose type is integer, float, string and so on. So a variable can be a string, an integer, or an object amount others. Now, within the Header class, you have "methods". This is what you refer to as "functions". The idea behind using classes is that you can take an Object Oriented approach to Programming. OOP for short OOP is where certain tasks are grouped into classes. A database connection is a perfect example of a class. Another typical class you will run across is a BBCode class. Now, you wouldn't add in a method to the BBcode class for calculating the average of an array's values. Doing so has absolutely nothing to do with BBcode. (Note: I'm not saying you are in violation of any of these concepts, but instead I'm laying them out for you so that you can see that the question of how fast something executes is not the reason why you would or wouldn't use a class. And it's not a reason for why you would or wouldn't add a method to a class either.) Therefore, we come to the conclusion that if the task you wish to perform makes sense to be grouped with the class you are thinking of putting that bit of code into, then by all means do so. If it doesn't, then na, don't put it in there. Now, that we've covered that, let's consider the question of variable scope. If you simply make a file, with no functions in it, and no classes, and then you include said file in another script, every variable in that script you just included is going to "exist" in the same scope as the script it is included into. However, if you put said code into a method, and then called that method, the variables in that method are NOT in the same scope as the script that method is called in. The variables will remain in that method's scope. If your class has any attributes, then those attributes would be available to all methods in the class by default. So class attributes have a scope that spans all of the methods in the class. Okay, I've spewed enough jibber jabber. But like I said, the question of how fast using a class is, is really a minor concern when the power of a class and the useability of a class can make your code better (especially if the code is something more than one person works on because it compartmentalizes the code)   The last thing I'll say is, you'll get more mileage out of optimizing the code in your classes, functions, includes, and scripts rather than trying to figure out if your code runs faster in a class, function, Include or otherwise.
  5. Re: Grouping and sums (need help) Beauty is in the eye of the beholder my dear ;) BTW, I've got some other ones that are pretty ridiculous looking. lol Normally I go with a join. In fact, I'm more used to them. Subqueries are really kinda new to me. lol Anyways, I will gladly accept the infamy of being the owner of the fugliest query award!
  6. Re: Grouping and sums (need help) It should be commissioned into a work of art of some kind. Perhaps a gold placard. Ya know what I kept missing, was the join. Normally joining a table is something I do with no thought, but the addition of a group by clause threw me off. So I kept trying to do a query like yours, but with a subquery for the sum, and that wasn't working out. So I crafted the query I ended up with by starting from the subquery, and working my way up to the outer query lol. I will say this, it opened a whole new thing for me. Subqueries in the from clause for making a custom table on the fly. :D But alas, you query most definitely runs faster than mine and the two queries will be swapped out. lol
  7. Re: Grouping and sums (need help) Yup, that works good :D I regard my query as a work of art, and hate to see it go. Thanks a bunch Nyna :D
  8. Re: Grouping and sums (need help)   select userid, sum(total_per_type) as total from ( select team1.userid, ( select count(*) * (select law1.salery from lawyer_types as law1 where law1.id = team1.lawyer_id) from my_lawyers as team2 where team2.userid = team1.userid and team2.lawyer_id = team1.lawyer_id) as total_per_type from my_lawyers as team1 group by team1.userid, team1.lawyer_id) as subquery group by userid   Well, it's fugly, but it works. :mrgreen:   Anyone think they can do better?
  9. Hey folks, I got a lil problem that is stumping me.   There are two tables. One is for lawyers that players own. The other is for lawyer types. For brevity, I'll list the needed tables, and column names.   Table: my_lawyers id --- auto incrementing primary key userid --- who the lawyer belongs to lawyer_id --- what kind of lawyer this is   [*]lawyer_types id --- auto incrementing primary key salery --- what is this lawyers weekly salery?     What I need is to find out how much each player will owe in lawyer salaries for the week. There is no quantity field in the my_lawyers table. Players could have 4 of the first type of lawyer, 3 of the second, and 2 of the third type. suppose the first type lawyer is paid 100 per week, the second 200, and the third 300, the query should do this lawyer type 1: 4 * 100 + lawyer type 2: 3 * 200 + lawyer type 3: 2 * 300 which would total 1600 The result of the query should provide one row, for every player that owns a lawyer. And this row should represent the total salery of all of that player's lawyers, and it should return that player's userid as well. If anyone can hit that up for me, that'd be great. I've come up with a few different queries, but all of them proved to return the wrong information. Thanks in advance to anyone that tries to figure this out :D
  10. Re: Local Sever On Linux Being a former Ubuntu user myself, I wish I could help you, but I'm confined to a windows machine at the moment. But I can tell you that the folks at ubuntuforums.org can help you, and I've found them to be willing to offer what seemed to me to be expert level advice. If I had a linux machine, I'd install lamp and see how it goes, but I don't Good luck!
  11. Re: Local Sever On Linux That forum would be the place to get detailed help with installing programs using linux Ubuntu Of course, if you just use the synaptic application manager, it will install it all for you. Ubuntu really is a snap to install things when you do it using the installation managers. It's a graphical interface. No need to compile, make, makefile and all that crap.
  12. Re: How many lines of code do you have?   Very true. And I don't fault anyone for doing that :D Of course every instance of copying lines can't be accounted for with this script. I skipped over the htmlpurifier code as there is quite a bit of code there that I didn't write, and although it could be included in the count, I wanted to know how many lines I wrote. Code generators, nope, can't say that I've used that. I do use an ajax javascript function over and over again. That function was not orginally writen by me. Every one of them has some amount of editing. I did include all of those since there is quite a bit of javascript that I did write, and there's no easy way to eliminate them. In the end, my total of 39k lines of code is an overestimate of how many lines I've written. It would be interesting to include the html purifier and any other 3rd party code just to see how many lines the entire project is.
  13. Re: How many lines of code do you have? Well, while I don't call into question anyone's claims (and I don't mean to suggest Decepti0n does either) I do have a lingering question in my mind as to how long it would take to write a million lines of code. So I did some calculations, because a number like 1 million is hard to grapple wholesale. Assuming an 8 hour day of work, 7 days a week, and writting code at a rate of 1 line every second solid during those 8 hours of every day, then it would take 34.7 days to write 1 million lines of code. If we assume that each line takes 30 seconds to write, and again assuming a 7 day work week, 8 hour work day, and a solid one line for every 30 seconds on the job, it would take 1041.7 days to write 1 million lines of code or 2.85 years (again, working every day, 8 hours per day, no breaks, and 1 line of code every 30 seconds.) It gets even crazier if we add in some other things. Let's say 20% of your time is spent thinking and not writing at all. That leaves 6.4 hours left. Then we'll take out a 30 minute lunch break. 5.9 hours. Then we'll assume a 5 day work week. (this adds in 2 days, for every 5 days in the final total) and if the final total goes over a year (which we know it will), we'll add in two weeks vacation time. lol With this scenario, we'll assume that the coder is coding at a solid rate of 1 line every 30 seconds while he/she is actively involved in coding. 1412.43 Days (before adding in weekends) 1977.40 Days (with weekends) That's 5.4 years Five vacations, two weeks each is 70 days. The grand total is 2047.40 days to write one million lines of code, working a solid 5.9 hours per day, writing one line of code every 30 seconds, taking two days off per week, taking a two week vacation every year.   Edit: I incorectly went from 6.4 hours to 6.1 hours adding in a lunch break. This of course resulted in faster coding times. The new calculation uses a 5.9 hour work day which is 30 minutes off of 6.4 hours. ;)
  14. Re: Best way to write this? I think he was thinking he could reference a table column from the sprintf argument section. This represents a fundamental error in how you see the sprintf function working.   sprintf(" QUERY STRING HERE ", ARGUMENTS HERE ); The argument section, is formated, and the string portion has the arguments inserted into it. You can't reference a column directly from the arguments section, because php combines that into the string. IN other words, the ARGUMENTS part, is not interpreted by MySQL. That sprintf only returns the; QUERY STRING HERE part. so if you do sprintf("QUERY STRING", maxenergy); maxenergy is interepreted by php as a constant, that is undefined (or else it could be defined, but it wouldn't hold the value of maxenergy in the users table) this constant, if it doesn't hold a value, is asigned the value: null so sprintf("QUERY STRING", null); This is equivalent to the last sprintf deal.   sprintf("QUERY maxenergy STRING", $userid); maxenergy MUST be inside the string, as it's intended to reference a table column directely You could do: sprintf("QUERY %s STRING", 'maxenergy'); as you can see maxenergy is surrounded by quotes, so now it's a string and not a constant.
  15. Re: Best way to write this? the way you added in money first will work, the second way you did it, won't money <<< needs to be inside the query string. ;)
  16. Re: Best way to write this? php will parse formatting a variable as a integer faster than it will parse escaping a string and then formatting it as a string. And yup, you got it ;) I'd recommend formatting in a format that is closest to the expected format you want. If you only want a number, then format it as a number. ;) The query itself, once php is done parsing it, it doesn't matter if you escaped a number, or if you formatted it as a number, mysql will run that query at the same speed.
  17. Re: Best way to write this?   $do = sprintf("UPDATE `users` SET `money`='%u' WHERE `userid`='%u' ", 50000, $userid); mysql_query($do);   The sprintf function takes the "arguments", that is the stuff at the end, and formats them the way you specify in the string at the beginning. %u and %d format the argument as an integer, and that makes escaping that argument unnescessary. If you use %s, then that argument would likely need to be escaped.
  18. You're saying to yourself, no it isn't. lol But yes it is! I'm feeling a bit lazy, so I'm not going to blog all over this post about what's happening here. However, take these three scripts, save them and put them all in the same folder on your local web server, or your remote web host. Then load up the html file and see ajax magic happening before you eyes. These three files are about as stripped down an ajax object can be. Enjoy!   Name this file: ajax_test.html <html> <head> <script src="ajax.js"></script> </head> <body> <div align="center"> <table> <tr> <th> <h2>Ajax Testing</h2> </th> </tr> <tr> <td> <ul> [*] [url="javascript:js_function_1('do_1')"]Option 1[/url] [*] [url="javascript:js_function_1('do_2')"]Option 2[/url] [*] [url="javascript:js_function_1('do_3')"]Option 3[/url] [*] [url="javascript:js_function_1('do_4')"]Option 4[/url] [*] [url="javascript:js_function_1('do_5')"]Option 5[/url] [/list] </td> </tr> </table> <span id="ajax_output"> All ajax output is sent here. </span> </div> </body> </html>   Name this file: ajax.js // create the Ajax request object. // This function NEVER needs to be modified. function ajax_create() { var ajax = false; // initialize the object: // Choose object type based upon what's supported: if (window.XMLHttpRequest) { // IE 7, Mozilla, Safari, Firefox, Opera, most browsers: ajax = new XMLHttpRequest(); return ajax } else if (window.ActiveXObject) { // Older IE browsers // Create type Msxml2.XMLHTTP, if possible: try { ajax = new ActiveXObject("Msxml2.XMLHTTP"); return ajax } catch (e1) { // Create the older type instead: try { ajax = new ActiveXObject("Microsoft.XMLHTTP"); return ajax } catch (e2) {} } } // Send an alert if the object wasn't created. if (!ajax) { alert ('Some page functionality is unavailable.'); } } // This function is what is called when the user clicks the link, and it uses the function above // with the ajax1 = ajax_create() line. function js_function_1(submission) { ajax_object = ajax_create() // Confirm that the object is usable: if (ajax_object) { // Call the PHP script. // Use the GET method. // Pass the username in the URL. ajax_object.open('get', './do_ajax.php?action='+encodeURIComponent(submission)); // Function that handles the responce: ajax_object.onreadystatechange = function() { if (ajax_object.readyState == 4 && ajax_object.status == 200) { handle_check() } } // Send the request: ajax_object.send(null); } else { // Can't use Ajax! document.getElementById('ajax_output').innerHTML = 'Please file a bug tracker report.'; } } // End of js_function_1() function. // Function that handles the response from the PHP script: function handle_check() { // Assign the returned value to a document element: document.getElementById('ajax_output').innerHTML = ajax_object.responseText; } // End of the handle_check() function.   Name this file: do_ajax.php <?php function do_1() { echo "This is the first function in the php file called by the ajax javascript."; } function do_2() { echo "This is the second function in the php file called by the ajax javascript."; } function do_3() { echo "This is the third function in the php file called by the ajax javascript."; } function do_4() { echo "This is the fourth function in the php file called by the ajax javascript."; } function do_5() { echo "This is the fifth function in the php file called by the ajax javascript."; } switch ($_REQUEST['action']) { case 'do_1': do_1(); break; case 'do_2': do_2(); break; case 'do_3': do_3(); break; case 'do_4': do_4(); break; case 'do_5': do_5(); break; } ?>
  19. Re: How to add in favorites hehe I've got enough temptations already! :D onload.... no no no no no, somebody stop me lol
  20. Re: Best way to write this? One could right a book on the topic of passing variables in the URL in the POST header. The first query you have there, dosn't need those escaping functions since you're casting the variable to an integer. You can't inject database code into a database if your input has been cast to an integer. so, the %u, with no escape, and escape if you are putting in a string. On the second on, that's exactly what you should do. hard coded: it's permanent. the opposite would be user submited data since that's always changing.
  21. Re: How to add in favorites OMG you gave out info on how to make a link to change a home page!! Ban mdshare :p Evil...... :mrgreen:
  22. Re: Best way to write this? Kudos! You're exploring new territory. Keep it up ;)     The second one is definitely the better one. About the only thing you could do is add in a "limit 1" since you most likely only want one row there.   Yes, and no. mysql real escape will protect you from injections, but the better way here, is to use the %d (or as nyna does, %u) to format as an integer. %u does not carry over a negative sign, if there is one, %d will allow negative numbers. If you cast the variable as an integer, you are that much more precise, and you save processing power. But over all, yes you *could* do it that way.     In this situation, remember that %s does no need quotes around it. You put in the quotes earlier because of how the mysql syntax works. Here you would use the back tick. You also did not have the string that is the argument in the mysql escaping function surounded with quotes (that's a php string so it needs to be surounded by quotes). And lastly, if the string is hard coded, i.e., permanent, why not just put the string in the query? Perhaps this is simply for the sake of testing, seeing what can be done. In which case, that's cool.  
  23. Re: How many lines of code do you have? It might be php >= 5 dependant. There's nothing this code depends on as far as php includes. It is being run on php 5.2.5, apache 1.3, and windows xp. There's no mysql involved. One thing about file systems, different operating systems will have to be compensated for. But if you have my set (perhaps apache version doesn't matter) it should run out of the box, if your php is up to date. Mccodes? I dun see how it's mccodes (kinda) lol But yeah, Nyna you are right, it's 100% my code ;)   Edit: Oh, and Will you're absolutely right about the time setting, I should have taken it out of there. I'm sure you can identify with making recursive functions and thinking, well, it took too long to execute, so perhaps I need to allow more time. Then ya find out that your code was just wrong. lol So yeah, it's a remnant. I'll edit it out.
  24. <?php # Count total line numbers /* Apply a recursive directory/file reading function that will total up how many lines all the .php and .js files in the directory, and sub-directories starting from where this file is placed. */ function line_counter($dir) { // echo "Dir: $dir ----------- <hr> "; $files = scandir($dir); static $count = 0; foreach ($files as $key =>$filename) { if (in_array($key, array(0,1)) or in_array($filename, array('purifier'))) { continue; } if (is_dir($dir.$filename)) { $new_path = $dir . $filename . '/'; line_counter($new_path); } else { $link_name = explode('.',$filename); if (!isset($link_name[1]) or !in_array($link_name[1], array('php', 'js')) ) { } else { $count += count(file($dir.$filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); } // echo "$dir.$filename<hr>"; } } return $count; } // End of line_counter() function. $count = line_counter('./'); echo "<h1>final tally: $count</h1>"; ?>   This code will recursively search through directories starting from where this script is placed, and count up how many lines of code are contained in your files. Uncomment this line, if you want to see all the directories searched. // echo "Dir: $dir ----------- <hr> ";   Uncomment this line of you want to see all the files that were included in the count. // echo "$dir.$filename<hr>";   This next line serves two purposes: 1. skip the . and .. which on my system are always the elements in the array with keys of 0 and 1. This is system dependant. You'll have to view the array using var dump or print_r on the $files array to see where it is on your system. 2. The second part filters out certain directories so they aren't included. I did not want third party libraries included in the count.   if (in_array($key, array(0,1)) or in_array($filename, array('purifier'))) {   This last part filters out file names that don't have an extension, or that don't have an extension we want to count. I chose to only count php and js files.   if (!isset($link_name[1]) or !in_array($link_name[1], array('php', 'js')) ) {   My count: final tally: 39672 Edit: was removed from the code, it's unnecessary.
  25. Floydian

    Adobe CS3

    Re: Adobe CS3 Depending on your definition of cheap, the adobe website will ship a copy out to you for what could potentially be viewed as cheap. lol
×
×
  • Create New...