Jump to content

KevinM1

Moderators
  • Posts

    5,222
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by KevinM1

  1. 1. Never, ever, ever use 'global' to pass data into a function. It's bad programming, pure and simple. Use the function's argument list. That's why it's there. 2. You don't use most of the variables you declare. 3. HTML elements cannot share names or ids. Think about it - a name or an id is supposed to be a unique identifier, right? Unique means one and only one. 4. Have you tried executing your code more than once? From what I can see, the display will only ever show 1 because you never assign the old values to anything. $text, in particular, is never initialized or assigned to. Like Thorpe said, re-read our earlier replies. I gave you a solution that works and can be easily modified to suit your needs. We're not going to spoon-feed you the answer, especially since this appears to be a homework problem. Instead of panicking, take a breath and truly look at the code I gave you. You have everything except the final solution. Try to see how it all connects.
  2. Book: http://www.amazon.com/gp/product/0321245652/ref=s9_simh_gw_p14_d5_i1?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=0HH9YVTWDYSW8PDR0NB9&pf_rd_t=101&pf_rd_p=470938631&pf_rd_i=507846 That's about as good a primer on beginning PHP you can find. Yes, that's right.
  3. Don't use 'global'. Pass the value into the function through its argument list.
  4. We have a stickied topic describing 'headers already sent' errors: http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Also name_id is not the same as $name_id.
  5. You don't have a button named submit in your form now. That means your PHP code at the top will never work. The superglobal $_POST array works by using the names of your HTML form inputs. $_POST['submit'] maps to <input type="submit" name="submit" value="submit" />, just as $_POST['username'] would map to something like <input type="text" name="username" />. Take note of the parts that are bold. Have you bought that book yet? You'll learn a lot more with a good book than reading free tutorials of questionable quality and throwing a bunch of code at the wall to see what actually sticks.
  6. Not as likely as MS were forced to display a promt to all IE users that other browsers are available. Not in the US, AFAIK.
  7. 1. I don't believe the original poster is writing OOP. 2. You can't extend methods.
  8. I can't imagine what it must have been like in the late 90's developing for early IE, Netscape Navigator, and AOL's mutant version of IE. Must make all the bitching about IE6 seem laughable.
  9. Just to be sure you're clear on this, when btherl mentions a class' interface, he's not referring to the built-in language construct named interface. Every class has an interface - the public fields and methods of that class. This interface is how the rest of your code interacts with your classes and objects. It creates and enforces particular lines of communication between the classes or objects and your client code. Why is this important? One of the key concepts of OOP is encapsulation. Objects should essentially be treated as black boxes. Data is entered or a request for data is made, but how that data or request is processed remains a mystery. All that matters, at least in the eyes of the client code, is that the right thing happened. One would expect a public method named getValue() to retrieve a value. How that value is actually obtained doesn't matter to your client code. This all leads into abstraction and polymorphism, other key concepts you'll need to learn if you want to do OOP right.
  10. What version of IE are you testing with? I ask because jQuery is officially supported by Microsoft, so at the very least it should work with IE8, if not IE7. EDIT: A quick look in IE9 Beta shows that it has something to do with the image layering. Looks like the top image is being placed on top of the actual link, causing it not to be clickable. I can still get the animation to work by clicking next to the image.
  11. The superglobal arrays are just that - always global, and thus always available. There has to be something else at play. Show us your real code.
  12. *raises hand* That would be me. @fortnox007: Do yourself a favor and get a solid JavaScript book. The free tutorials that can be found online are a minefield of outdated info that show how to do it wrong. Even a site like w3schools, which shows proper syntax, fail to mention best practices. JavaScript is just quirky enough where not knowing why to do something can ruin an entire script and leave you baffled. Look through the archives of this forum and see how many scripts were doomed from the start because the person writing them thought that JavaScript behaved like PHP, or because they took some example code from somewhere that worked, but wouldn't work on their own project. Something from O'Reilly Press would probably do the trick.
  13. This is one of those tricky situations that tends to confuse OOP newbies. The question is really how often will the part that differs (page 2, in your situation) crop up elsewhere in your project? If it's a one-time thing, I don't see anything 'wrong' with simply using a default parameter: public function getBoxContents($user = null) { if($user) // if user exists, this is the page 2 functionality { // do page 2 stuff and return } else { // do normal processing and return } } Keep in mind that this is really for those one-time exceptions that you may not feel warrant an entirely new class of objects to address. Otherwise, create a child object like Andy-H showed. Note: personally, I'd still more than likely create a new class anyway. I don't like this kind of branching logic in my data objects. Also note that this kind of debate (small bit of branching logic vs. a one-time-use specialty object) still rages today.
  14. Don't post in a thread that's over a month old unless it's to bump it with new, relevant information. Thank you.
  15. You mean an English speaking country? I'm from England and speak English pretty well. Funny how that works....
  16. You'll need a pivot table. Essentially, something like this: An OOP approach would help, too. A Person object could have fields containing their db id, the ids of their parents, siblings, and direct descendants.
  17. Here's what you should learn in addition to PHP: 1. HTML. PHP is primarily used for websites. HTML is the language that browsers read to construct and display sites. 2. CSS. Cascading Style Sheets, which are used in conjunction with HTML. 3. A database of some sort. MySQL is essentially the default choice. 4. JavaScript. This is where the web is moving, for better or worse. 5. Object Oriented Programming (OOP). OOP is a programming methodology, so it's not something tied just to PHP. Still, it's the industry standard way of programming. Books on PHP: Start with: http://www.amazon.com/PHP-World-Wide-Web-Second/dp/0321245652/ref=sr_1_2?s=books&ie=UTF8&qid=1284562565&sr=1-2 It's about as good a primer on the language you can find, and it's gentle to absolute beginners. It talks about the old version of PHP (4), but there's nothing in here that's different than the current version. Then, go to: http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X/ref=sr_1_3?s=books&ie=UTF8&qid=1284562781&sr=1-3 Your primer for both OOP and PHP 5. This should get you started.
  18. FWIW, the future of PHP is a bit fuzzy at the moment. Version 6 has been axed - the features it was supposed to add (late static binding, namespaces, etc.) are slowly being released as new versions of PHP 5. AFAIK, there is no version 6 road map right now. Facebook has been doing some interesting things with PHP. Look here: http://developers.facebook.com/blog/post/358 Aside from that, I'm not sure if there's a clear vision of the future of the language. PHP 5 has been around for, what, 5 or 6 years? And Zend doesn't follow a rigid release schedule like, say, Microsoft which releases a new version of .NET every 2 years like clockwork.
  19. I believe one of $_SERVER['SCRIPT_NAME'] or $_SERVER['SCRIPT_FILENAME'] does that.
  20. jQuery/JavaScript gallery, brand new (just got the link through my Twitter feed a few minutes ago): http://manos.malihu.gr/sideways-jquery-fullscreen-image-gallery Since it's all JavaScript and CSS, you can re-skin it.
  21. I don't mind the red. You may want to tone it down minutely, but it's not garish or anything.
  22. Very nice. *thumbs up*
  23. Yeah, IE can be a bit tricky. Your best bet is to use a CSS reset. One of the standard ones can be found here: http://meyerweb.com/eric/tools/css/reset/reset.css Let us know if you need more help with it (e.g., what a reset is, why it's necessary, how to use it, etc.).
  24. Solution: <?php if(isset($_POST['submit'])) { $buttonVal = $_POST['num']; } ?> <!doctype html> <html lang="en-us"> <head> <title>Example</title> </head> <body> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post"> 1 <input name="num" type="radio" value="1" /> 2 <input name="num" type="radio" value="2" /> <br /><br /> Number entered: <input name="display" type="text" value="<?php if(isset($buttonVal)){ echo $buttonVal; } ?>" /> <input name="submit" type="submit" value="Submit" /> </form> </body> </html> Notice that there's: 1. No function. For something this simple, no function is necessary. 2. No JavaScript, which was one of your main problems from before.
  25. No offense, but since you clearly don't grasp the difference between PHP and JavaScript, let alone how to use them together, I'd say you have more problems than just writing functions. As for books, the Visual Quickstart Guide for PHP is pretty good. In general, books from either O'Reilly Publishing or APress Publishing are good.
×
×
  • 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.