Jump to content

roopurt18

Staff Alumni
  • Posts

    3,746
  • Joined

  • Last visited

    Never

Everything posted by roopurt18

  1. mjdamato has the best solution, except in MySQL it's a single equal signs, not a double.
  2. You should always use single quotes around associative array keys (unless they are defined as a constant of course). echo $array['someKey']; If you are going to embed variables in double quoted strings, then you should always enclose them in curly brackets, whether or not they are arrays. $var = 'Hello'; $var2 = Array( 'msg' => 'World' ); echo "{$var}, {$var2['msg']}"; These are what I would consider to be "best practices," as they help avoid errors from sloppy coding. BTW, I'm not sure what the exact reason for the error is; at first I was inclined to say it was a parsing error but I'm not so sure that would be the case. It doesn't matter though if you follow the best practices I outlined above.
  3. You need to be really careful allowing PHP to be entered. If a user of your CMS has their account compromised then an attacker will be able to do all sorts of stuff on the server.
  4. You should also usually call exit() after redirecting.
  5. Oh, for the record, I didn't have anything to do with the original. I'll wait for some more replies before I say anything more; I don't want to seed my feed back!
  6. I'm doing a redesign of my dojo's website. Here is the original: http://www.japankaratedofed.com/ Here is my current work in progress. http://www.rbredlau.com/test/jkf/ Right now I'm interested in thoughts and opinions on the color scheme. Also I was thinking a background image might make it nicer, either something tiled or maybe a gray-scale image of Japan or something. (Yah I'm aware the body needs some padding, no need to comment on that.)
  7. So I've got a situation where I'm not sure what the best way to proceed is. Firstly, the web system I maintain imports data from an external source. Each time it does this import it wipes out all existing data and replaces it with the new incoming data. For example, if the `projects` table is importing, all existing projects are wiped out and replaced with the incoming data. This has the negative side effect that the web system is entirely data dependent on the other application and can not stand on its own as a product. I'm doing some redesign so that it can become a stand-alone system. Following are sample descriptions of the tables. Here is my incoming data format: projects pro_code VARCHAR(6) # project code name VARCHAR(32) # project name Here is my project table on the web: x2_projects id PRIMARY KEY AUTO_INCREMENT etc. name VARCHAR(32) # project name dsrc TINYINT # data source, 2 indicates origin is from importation created DATETIME modified TIMESTAMP Here is the table I use to keep track of imported projects and their assigned web ID x2_impids_projects wv_id INT # web id, i.e. x2_projects.id pro_code VARCHAR() # project code, i.e. projects.pro_code Here is what I'm currently doing: Creating a temp table from `projects`, adding a `wv_id` column (default 0), and SELECT'ing all data from `projects` Updating `temp`.`wv_id` using `x2_impids_projects` so that all projects in the temp table will have their corresponding wv_id; this way I know if the wv_id is zero it's a new project, if it's non-zero it's an existing project Updating `x2_projects` from the temp table I need to insert the projects from the temp table into the web table, which is easy. I then need to update the `x2_impids_projects` table with the auto_incrementing id and the pro_code that it was attached to, but by now I've lost the ability to connect that information. So here's the question. Would it be better to: 1) Perform an alter table on `x2_projects` and add a `pro_code` column. I could then update `x2_impids_projects` very easily and then drop the `pro_code` column. This is the easier option IMO. 2) Alternatively, when creating the temp table I can add an auto_incrementing field and set it's value to the next value that would occur in `x2_projects`. I would have to lock `x2_projects`, create the temp table, populate the temp table, update `x2_impids_projects`, insert and update on `x2_projects`, and finally release the lock. This is the safer option as all of the work occurs in the temp area and if it chokes there's less chance of affecting the live table. However, I'm not entirely sure how to go about getting the next auto_increment id out of the existing table. So I'm looking for opinions and suggestions. I'm also concerned about performance (who isn't); most of these tables are pretty small, less than 1k records. However, some of them are quite large, but nothing more than 100k records AFAIK. Thanks in advance.
  8. As far as I can tell that has to appear in all pages coming from all of the involved domains. I have no idea what the repercussions would be if you had an iframe receiving JSON as its contents because you wouldn't to add tags to that output, if you know what I mean. I remember reading about that solution in an O'Reilly book on JavaScript, but it wasn't applicable in my situation as I can't control all of the code. If it doesn't work out for you I might be able to assist further.
  9. You should find plenty of tutorials, hints, and / or suggestions from this Google search: http://www.google.com/search?q=Javascript+event+model Specifically, you want to look for tutorials that show you how to use JavaScript code like: addEventListener(); // netscape, opera, firefox attachEvent(); // internet explorer Any tutorials that show you how to do the following should be avoided: <a href="http://www.google.com" onclick="some_javascript();">Click here</a> The short version is HTML, CSS, JavaScript, etc. should all be separate. You should not be placing JavaScript in your markup, least of all for events. The event models exposed by IE and mozilla browsers make event handlers within the markup unnecessary; it is a slight pain to work with two different event models, but the payoff is well worth it. I even took the time to create a JavaScript Events interface that wraps up both models into a single interface, thus making event handling a breeze for me. As far as the DOM is concerned, you want to learn how to use methods like document.getElementById(), document.createElement(), etc. W3Schools has some good DOM tutorials (and likely some good events tutorials as well). If you want it all wrapped up in a book, I recommend: http://www.oreilly.com/catalog/jscript3/ Lastly, I have an article dealing with attaching events to an iframe which might help you as well: http://www.rbredlau.com/drupal/node/7
  10. If you can control the code in both places then you might be in luck with an easy solution, found here: http://jszen.blogspot.com/2005/03/cross-domain-security-woes.html In my situation, I was only able to control the code in one of the locations, so the solution I had to come up with was a little more involved.
  11. You're trying to handle framework errors, not errors in your users' controllers or models. The try / catch blocks belong inside your framework. For the catch, you should try and handle the error, but if you can't you can error out and kill the script. The users of your framework can still use try / catch blocks in their client code for their own purposes.
  12. Getting the comment box to display under the clicked link is a Javascript problem. The short answer is if you use the Javascript event model correctly, the event handler will receive a reference to the node that caused the event. From there you can very easily create and insert a textarea with the DOM.
  13. $users_age=strpos('profile.php',$age); if($age<18||$users_age>18) If profile.php is a script, it's very likely not going to have a user's age embedded within it. Anyways, you're telling PHP to look for whatever is in $age within the string 'profile.php'. In all likelihood you want to pull each person's age from the database and compare them, and that is only if they are not contained within memory already.
  14. I don't see why you had to go and create a second topic on this. But... The logic you want is: If both users are under 18 OR both users are 18 and over Then they can add each other. if($age1 < 18 && $age2 < 18 || $age1 >= 18 && $age2 >= 18){ // then add }else{ // fail } But I don't see this is a very realistic solution. Why should a 17 year old not be able to add an 18 year old (assuming this is a facebook or myspace type site)?
  15. PHP Monkey http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
  16. So what's the problem? What have you tried? What did or didn't work?
  17. Best keyboard I've ever owned: http://www.newegg.com/Product/Product.aspx?Item=N82E16823109026 Pros: Curved design Cheap Full sized arrow keys No F-Lock key (I hate the bastard that invented that) Meets your requirements as far as I can tell Cons: I can only use one at a time I used to be a big gamer, MMOs for the most part, and I would bind stuff to the function keys. Well then they started coming out with f-lock keyboards and it'd screw up the function key binds in games, so I immediately hated any keyboard with one of those. I require all of my keyboards to be curved or split design; while this one isn't a total split, it's curved enough that it's just right. Way, way, way back I had a MS split keyboard with mini arrow keys that I absolutely hated; who puts the arrow keys in 3 rows? The keyboard is responsive and works well. Also, I don't use wireless keyboards or mice, so the fact that it's wired also isn't a problem for me. As far as something that will last, with a keyboard this cheap, as long as it makes it 6 months to a year you're still coming out ahead of these $70 keyboards I see (which are utter crap IMO). The first one of these I bought at Frys on the spot when I saw it. In fact I loved it so much that I bought two, just in case one broke and I wouldn't be able to find it again. If you have a frys nearby they still usually stock them, so you can test it out first.
  18. I've always felt everyone is entitled to their own opinion, no matter how wrong they might be.
  19. If you told us why you needed it, then we could perhaps tell you the best way to accomplish your goal in PHP.
  20. For what purpose? An associative array is likely implemented as a hash table under the hood.
  21. Where exactly are you getting this data? And what formula are you using to calculate the score? If you're using MySQL you might be able to just shove everything over to the DB engine and have it sort the results for you.
  22. I don't understand why you can't use the score as the key. In instances where you have a collision (i.e. duplicate score) just turn the value into an array.
  23. The graph one has been one of my favorites for a long time. In 1999 I took a course called 'Graphs, Games, and Structures.' In reality the course really should have been called 'Graphs, Graphs, Graphs, and a Shit-Ton More About Graphs.' The only graphs I'd ever seen were those from math, i.e. 2 and 3 dimensional coordinate graphs. The idea of dots and lines being a graph was silly at best. We had all sorts of problems with graphs. Prove this about a graph with these qualities. Prove this about a graph with those qualities. If a graph has these qualities, what else do we automatically know about it? Then there are algorithms for working with graphs. Turns out the city-distance and traveling salesman problems are easily solved when represented as graphs. But the problems I hated most in that class were the ones where they'd show a graph, like I did, and ask us to rearrange it so that none of the lines overlapped. Some of these were very, very difficult and my friend and I used to always get pissed. I still remember my friend having an outburst in the library: "$%#*!!! <throws pencil> Why does it matter if the $@*@(#$ lines overlap or not?!" So that was 1999. Fast forward to sometime in 2003 or 2004. I'm sitting in my digital electronics course designing a circuit and then it hits me. All of a sudden I thought of every circuit board I'd ever looked at, those green boards with the thin silver lines running all over them. <i>Of course! An electronic circuit is a graph! And since they carry voltage you can't have wires that overlap each other.</i> So I excitedly tell my professor about my epiphany. He smiles and agrees with me. But then I have another realization... I say to him, <i>But no one is going to throw out a great engineering design just because they can't fit it on a circuit board. So they must have a way of making such overlapping circuits a reality?</i> <i>They just use multiple boards and layer them.</i> Doh! Too easy. I should have thought of that. So think of the situation where you have a massively complex circuit board with hundreds of dots and hundreds of lines and they can't overlap. I think (I'm not an engineer so I don't know) you'd use graph theory to recursively design each layer so that it has as many lines on it as possible in order to design a motherboard with as few layers as possible. Now one person might say, "Well who cares if theres 3 layers or 6?" But when 3 layers costs 1.5 cents and 6 layers costs 2.5 cents and you're planning on manufacturing 2 billion of them, the businessman certainly cares. Totally unrelated, here's another fun one. Let's say you're at AMD's manufacturing plant where they make AMD64 X2s. What's the difference between the assembly line that makes the 2.4Ghz CPUs and the one that makes the 2.5Ghz CPUs?
  24. Looking at other programmers' code and deciphering it is not even scratching the surface of the topics covered by a CS degree. If you were asked to create a chess program such that the program initially only knew what the legal moves were, but had to learn strategies based on games versus human opponents, would you even know where to begin? The following is the fibonacci sequence: f(n) = f(n - 1) + f(n - 2) f(2) = f(1) = 1 Could you implement this in a program? In your implementation, how long would it take for a call to f(200) to execute? How many times would f(17) be called if I were to call f(200)? If you had a list of cities and distances between them, how would you go about finding the shortest path between any two cities without having to compute every possible combination? Could you write an algorithm that could visited each city only once and minimized overall travel time? Following is a graph: Can you arrange the dots on this graph such that none of the lines are overlapping? Can you think of a practical application for such an exercise within the field of computing? You want to create a website where programmers can upload their source code for other programmers to look at. You want your site to display syntax highlighting when displaying code. Can you do this with a single generic program that doesn't have custom functions for each supported language (such as display_php_source(), display_cpp_source(), display_lisp_source(), etc.)? Can you create a compression program? Can you create an encryption / decryption program? There's a lot of topics encompassed by computer science and even the items I listed are barely scratching the surface. You don't go to college to learn how to program; a book can do that (and much cheaper too).
×
×
  • 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.